Skip to content

Commit 4c82397

Browse files
committed
feat: Add a script to update showcased projects' stars
1 parent b32fff4 commit 4c82397

File tree

2 files changed

+149
-22
lines changed

2 files changed

+149
-22
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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()

src/textual/demo/projects.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,93 +35,92 @@ class ProjectInfo:
3535
"Posting",
3636
"Darren Burns",
3737
"https://posting.sh/",
38-
"""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. """,
39-
"6.0k",
38+
"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. ",
39+
"9.5k"
4040
),
4141
ProjectInfo(
4242
"Memray",
4343
"Bloomberg",
4444
"https://github.com/bloomberg/memray",
45-
"""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.""",
46-
"13.3k",
45+
"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.",
46+
"14.1k"
4747
),
4848
ProjectInfo(
4949
"Toolong",
5050
"Will McGugan",
5151
"https://github.com/Textualize/toolong",
52-
"""A terminal application to view, tail, merge, and search log files (plus JSONL).""",
53-
"3.2k",
52+
"A terminal application to view, tail, merge, and search log files (plus JSONL).",
53+
"3.5k"
5454
),
5555
ProjectInfo(
5656
"Dolphie",
5757
"Charles Thompson",
5858
"https://github.com/charles-001/dolphie",
5959
"Your single pane of glass for real-time analytics into MySQL/MariaDB & ProxySQL",
60-
"649",
60+
"852"
6161
),
6262
ProjectInfo(
6363
"Harlequin",
6464
"Ted Conbeer",
6565
"https://harlequin.sh/",
66-
"""Portable, powerful, colorful. An easy, fast, and beautiful database client for the terminal.""",
67-
"3.7k",
66+
"Portable, powerful, colorful. An easy, fast, and beautiful database client for the terminal.",
67+
"4.7k"
6868
),
6969
ProjectInfo(
7070
"Elia",
7171
"Darren Burns",
7272
"https://github.com/darrenburns/elia",
73-
"""A snappy, keyboard-centric terminal user interface for interacting with large language models.
74-
Chat with Claude 3, ChatGPT, and local models like Llama 3, Phi 3, Mistral and Gemma.""",
75-
"1.8k",
73+
"A snappy, keyboard-centric terminal user interface for interacting with large language models.",
74+
"2.2k"
7675
),
7776
ProjectInfo(
7877
"Trogon",
7978
"Textualize",
8079
"https://github.com/Textualize/trogon",
8180
"Auto-generate friendly terminal user interfaces for command line apps.",
82-
"2.5k",
81+
"2.6k"
8382
),
8483
ProjectInfo(
8584
"TFTUI - The Terraform textual UI",
8685
"Ido Avraham",
8786
"https://github.com/idoavrah/terraform-tui",
8887
"TFTUI is a powerful textual UI that empowers users to effortlessly view and interact with their Terraform state.",
89-
"1k",
88+
"1.1k"
9089
),
9190
ProjectInfo(
9291
"RecoverPy",
9392
"Pablo Lecolinet",
9493
"https://github.com/PabloLec/RecoverPy",
95-
"""RecoverPy is a powerful tool that leverages your system capabilities to recover lost files.""",
96-
"1.3k",
94+
"RecoverPy is a powerful tool that leverages your system capabilities to recover lost files.",
95+
"1.5k"
9796
),
9897
ProjectInfo(
9998
"Frogmouth",
10099
"Dave Pearson",
101100
"https://github.com/Textualize/frogmouth",
102-
"""Frogmouth is a Markdown viewer / browser for your terminal, built with Textual.""",
103-
"2.5k",
101+
"Frogmouth is a Markdown viewer / browser for your terminal, built with Textual.",
102+
"2.8k"
104103
),
105104
ProjectInfo(
106105
"oterm",
107106
"Yiorgis Gozadinos",
108107
"https://github.com/ggozad/oterm",
109108
"The text-based terminal client for Ollama.",
110-
"1k",
109+
"2.0k"
111110
),
112111
ProjectInfo(
113112
"logmerger",
114113
"Paul McGuire",
115114
"https://github.com/ptmcg/logmerger",
116115
"logmerger is a TUI for viewing a merged display of multiple log files, merged by timestamp.",
117-
"162",
116+
"183"
118117
),
119118
ProjectInfo(
120119
"doit",
121120
"Murli Tawari",
122-
"https://github.com/kraanzu/dooit",
121+
"https://github.com/dooit-org/dooit",
123122
"A todo manager that you didn't ask for, but needed!",
124-
"2.1k",
123+
"2.6k"
125124
),
126125
]
127126

0 commit comments

Comments
 (0)