Last active
November 5, 2025 19:11
-
-
Save mdmitry1/35cdfd7bdd8b2daffb12f54dec5f7c52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3.14 | |
| """Query GitHub API""" | |
| from datetime import datetime | |
| from urllib.request import urlopen | |
| from pprint import pformat | |
| from sys import argv | |
| import json | |
| from os import popen | |
| def user_time(login): | |
| url = 'https://api.github.com/users/' + login | |
| resp = urlopen(url) | |
| reply = json.load(resp) | |
| # show reply with cornsilk1 background for readability | |
| print(color_bg(pformat(reply))) | |
| # "2008-01-14T04:33:35Z", we trim the 'Z' with [:-1] | |
| ts = reply['created_at'] | |
| created = datetime.fromisoformat(ts[:-1]) | |
| return datetime.now() - created | |
| def hex_to_rgb(h): | |
| """Convert a hex color string to an (r, g, b) tuple. | |
| Accepts formats like '#fff', 'fff', '#ffffff' or 'ffffff'. | |
| """ | |
| h = h.lstrip('#') | |
| if len(h) == 3: | |
| h = ''.join([c * 2 for c in h]) | |
| return tuple(int(h[i:i+2], 16) for i in (0, 2, 4)) | |
| def color_bg(text, hexcolor="#FFF8DC"): | |
| """Wrap text with ANSI escape codes to set the background to the given hex color. | |
| Uses 24-bit truecolor escape (48;2;r;g;b). Default is cornsilk (hex #FFF8DC), | |
| which corresponds to the X11 color "cornsilk1" commonly used in GUI palettes. | |
| """ | |
| r, g, b = hex_to_rgb(hexcolor) | |
| return f"\x1b[48;2;{r};{g};{b}m{str(text)}\x1b[0m" | |
| def main(args): | |
| if(len(args) < 2): | |
| owner=popen("gh repo list --json owner -q '.[0].owner.login'").read().strip() | |
| print(color_bg(user_time(owner))) | |
| else: | |
| print(color_bg(user_time(args[1]))) | |
| if "__main__" == __name__: main(argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment