|
| 1 | +import httpx |
| 2 | +import re |
| 3 | +from os import path |
| 4 | +from rich.console import Console |
| 5 | +console = Console() |
| 6 | +error_console = Console(stderr=True, style="bold red") |
| 7 | +def main() -> None: |
| 8 | + to_replace = "" |
| 9 | + template = '\n ProjectInfo(\n "<repo>",\n "<creator>",\n "<url>",\n "<description>",\n "<stars>"\n ),' |
| 10 | + # dictionary of items to replace |
| 11 | + dictionary = { |
| 12 | + "repos": [ |
| 13 | + "Posting", |
| 14 | + "Memray", |
| 15 | + "Toolong", |
| 16 | + "Dolphie", |
| 17 | + "Harlequin", |
| 18 | + "Elia", |
| 19 | + "Trogon", |
| 20 | + "TFTUI - The Terraform textual UI", |
| 21 | + "RecoverPy", |
| 22 | + "Frogmouth", |
| 23 | + "oterm", |
| 24 | + "logmerger", |
| 25 | + "doit", |
| 26 | + ], |
| 27 | + "creator": [ |
| 28 | + "Darren Burns", |
| 29 | + "Bloomberg", |
| 30 | + "Will McGugan", |
| 31 | + "Charles Thompson", |
| 32 | + "Ted Conbeer", |
| 33 | + "Darren Burns", |
| 34 | + "Textualize", |
| 35 | + "Ido Avraham", |
| 36 | + "Pablo Lecolinet", |
| 37 | + "Dave Pearson", |
| 38 | + "Yiorgis Gozadinos", |
| 39 | + "Paul McGuire", |
| 40 | + "Murli Tawari", |
| 41 | + ], |
| 42 | + "url": [ |
| 43 | + "https://posting.sh/", |
| 44 | + "https://github.com/bloomberg/memray", |
| 45 | + "https://github.com/Textualize/toolong", |
| 46 | + "https://github.com/charles-001/dolphie", |
| 47 | + "https://harlequin.sh/", |
| 48 | + "https://github.com/darrenburns/elia", |
| 49 | + "https://github.com/Textualize/trogon", |
| 50 | + "https://github.com/idoavrah/terraform-tui", |
| 51 | + "https://github.com/PabloLec/RecoverPy", |
| 52 | + "https://github.com/Textualize/frogmouth", |
| 53 | + "https://github.com/ggozad/oterm", |
| 54 | + "https://github.com/ptmcg/logmerger", |
| 55 | + "https://github.com/dooit-org/dooit" |
| 56 | + ], |
| 57 | + "description": [ |
| 58 | + "Posting is an HTTP client, not unlike Postman and Insomnia. As a TUI application, it can be used over SSH and enables efficient keyboard-centric workflows. ", |
| 59 | + "Memray is a memory profiler for Python. It can track memory allocations in Python code, in native extension modules, and in the Python interpreter itself.", |
| 60 | + "A terminal application to view, tail, merge, and search log files (plus JSONL).", |
| 61 | + "Your single pane of glass for real-time analytics into MySQL/MariaDB & ProxySQL", |
| 62 | + "Portable, powerful, colorful. An easy, fast, and beautiful database client for the terminal.", |
| 63 | + "A snappy, keyboard-centric terminal user interface for interacting with large language models.", |
| 64 | + "Auto-generate friendly terminal user interfaces for command line apps.", |
| 65 | + "TFTUI is a powerful textual UI that empowers users to effortlessly view and interact with their Terraform state.", |
| 66 | + "RecoverPy is a powerful tool that leverages your system capabilities to recover lost files.", |
| 67 | + "Frogmouth is a Markdown viewer / browser for your terminal, built with Textual.", |
| 68 | + "The text-based terminal client for Ollama.", |
| 69 | + "logmerger is a TUI for viewing a merged display of multiple log files, merged by timestamp.", |
| 70 | + "A todo manager that you didn't ask for, but needed!", |
| 71 | + ], |
| 72 | + "repo_url_part": [ |
| 73 | + "darrenburns/posting", |
| 74 | + "bloomberg/memray", |
| 75 | + "Textualize/toolong", |
| 76 | + "charles-001/dolphie", |
| 77 | + "tconbeer/harlequin", |
| 78 | + "darrenburns/elia", |
| 79 | + "Textualize/trogon", |
| 80 | + "idoavrah/terraform-tui", |
| 81 | + "PabloLec/RecoverPy", |
| 82 | + "Textualize/frogmouth", |
| 83 | + "ggozad/oterm", |
| 84 | + "ptmcg/logmerger", |
| 85 | + "dooit-org/dooit", |
| 86 | + ], |
| 87 | + } |
| 88 | + for index in range(len(dictionary["repo_url_part"])): |
| 89 | + # get each repo |
| 90 | + console.log(f"Checking {dictionary['repo_url_part'][index]}") |
| 91 | + response = httpx.get( |
| 92 | + f"https://api.github.com/repos/{dictionary['repo_url_part'][index]}" |
| 93 | + ) |
| 94 | + if response.status_code == 200: |
| 95 | + # get stargazers |
| 96 | + stargazers = response.json()["stargazers_count"] |
| 97 | + if stargazers // 1000 != 0: |
| 98 | + # humanize them |
| 99 | + stargazers = f"{stargazers // 1000}.{(stargazers % 1000) // 100}k" |
| 100 | + # replace them |
| 101 | + to_replace += ( |
| 102 | + template.replace("<repo>", dictionary["repos"][index]) |
| 103 | + .replace("<creator>", dictionary["creator"][index]) |
| 104 | + .replace("<url>", dictionary["url"][index]) |
| 105 | + .replace("<description>", dictionary["description"][index]) |
| 106 | + .replace("<stars>", str(stargazers)) |
| 107 | + ) |
| 108 | + elif response.status_code == 403: |
| 109 | + # gh api rate limited |
| 110 | + error_console.log("GitHub has received too many requests and started rate limiting.") |
| 111 | + exit(1) |
| 112 | + else: |
| 113 | + # any other reason |
| 114 | + print(f"GET https://api.github.com/repos/{dictionary['repo_url_part']} returned status code {response.status_code}") |
| 115 | + # replace |
| 116 | + console.log("Fixing projects.py") |
| 117 | + with open(path.join(path.dirname(__file__), "projects.py"), "r") as projects_script_file: |
| 118 | + projects_file = projects_script_file.read() |
| 119 | + # find a pattern to replace |
| 120 | + search_pattern = r"PROJECTS = \[([^\]]+)\]" |
| 121 | + search_match = re.search(search_pattern,projects_file) |
| 122 | + if search_match: |
| 123 | + projects_file = projects_file.replace(search_match.group(1), to_replace + "\n") |
| 124 | + with open(path.join(path.dirname(__file__), "projects.py"), "w") as projects_script_file: |
| 125 | + projects_script_file.write(projects_file) |
| 126 | + console.log("Done!") |
| 127 | +if __name__ == "__main__": |
| 128 | + main() |
0 commit comments