Skip to content

Commit 87aa6b1

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

File tree

4 files changed

+184
-117
lines changed

4 files changed

+184
-117
lines changed

src/textual/demo/_project_data.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class ProjectInfo:
6+
"""Dataclass for storing project information."""
7+
8+
title: str
9+
author: str
10+
url: str
11+
description: str
12+
repo_url_part: str
13+
14+
15+
PROJECTS = [
16+
ProjectInfo(
17+
"Posting",
18+
"Darren Burns",
19+
"https://posting.sh/",
20+
"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. ",
21+
"darrenburns/posting",
22+
),
23+
ProjectInfo(
24+
"Memray",
25+
"Bloomberg",
26+
"https://github.com/bloomberg/memray",
27+
"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.",
28+
"bloomberg/memray",
29+
),
30+
ProjectInfo(
31+
"Toolong",
32+
"Will McGugan",
33+
"https://github.com/Textualize/toolong",
34+
"A terminal application to view, tail, merge, and search log files (plus JSONL).",
35+
"Textualize/toolong",
36+
),
37+
ProjectInfo(
38+
"Dolphie",
39+
"Charles Thompson",
40+
"https://github.com/charles-001/dolphie",
41+
"Your single pane of glass for real-time analytics into MySQL/MariaDB & ProxySQL",
42+
"charles-001/dolphie",
43+
),
44+
ProjectInfo(
45+
"Harlequin",
46+
"Ted Conbeer",
47+
"https://harlequin.sh/",
48+
"Portable, powerful, colorful. An easy, fast, and beautiful database client for the terminal.",
49+
"tconbeer/harlequin",
50+
),
51+
ProjectInfo(
52+
"Elia",
53+
"Darren Burns",
54+
"https://github.com/darrenburns/elia",
55+
"A snappy, keyboard-centric terminal user interface for interacting with large language models.",
56+
"darrenburns/elia",
57+
),
58+
ProjectInfo(
59+
"Trogon",
60+
"Textualize",
61+
"https://github.com/Textualize/trogon",
62+
"Auto-generate friendly terminal user interfaces for command line apps.",
63+
"Textualize/trogon",
64+
),
65+
ProjectInfo(
66+
"TFTUI - The Terraform textual UI",
67+
"Ido Avraham",
68+
"https://github.com/idoavrah/terraform-tui",
69+
"TFTUI is a powerful textual UI that empowers users to effortlessly view and interact with their Terraform state.",
70+
"idoavrah/terraform-tui",
71+
),
72+
ProjectInfo(
73+
"RecoverPy",
74+
"Pablo Lecolinet",
75+
"https://github.com/PabloLec/RecoverPy",
76+
"RecoverPy is a powerful tool that leverages your system capabilities to recover lost files.",
77+
"PabloLec/RecoverPy",
78+
),
79+
ProjectInfo(
80+
"Frogmouth",
81+
"Dave Pearson",
82+
"https://github.com/Textualize/frogmouth",
83+
"Frogmouth is a Markdown viewer / browser for your terminal, built with Textual.",
84+
"Textualize/frogmouth",
85+
),
86+
ProjectInfo(
87+
"oterm",
88+
"Yiorgis Gozadinos",
89+
"https://github.com/ggozad/oterm",
90+
"The text-based terminal client for Ollama.",
91+
"ggozad/oterm",
92+
),
93+
ProjectInfo(
94+
"logmerger",
95+
"Paul McGuire",
96+
"https://github.com/ptmcg/logmerger",
97+
"logmerger is a TUI for viewing a merged display of multiple log files, merged by timestamp.",
98+
"ptmcg/logmerger",
99+
),
100+
ProjectInfo(
101+
"doit",
102+
"Murli Tawari",
103+
"https://github.com/dooit-org/dooit",
104+
"A todo manager that you didn't ask for, but needed!",
105+
"dooit-org/dooit",
106+
),
107+
]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import httpx
2+
import os
3+
import json
4+
from rich.console import Console
5+
6+
# Not using the Absolute reference because
7+
# I can't get python to run it.
8+
from _project_data import PROJECTS
9+
10+
console = Console()
11+
error_console = Console(stderr=True, style="bold red")
12+
13+
14+
def main() -> None:
15+
STARS = {}
16+
17+
for project in PROJECTS:
18+
# get each repo
19+
console.log(f"Checking {project.repo_url_part}")
20+
response = httpx.get(f"https://api.github.com/repos/{project.repo_url_part}")
21+
if response.status_code == 200:
22+
# get stargazers
23+
stargazers = response.json()["stargazers_count"]
24+
if stargazers // 1000 != 0:
25+
# humanize them
26+
stargazers = f"{stargazers / 1000:.1f}k"
27+
else:
28+
stargazers = str(stargazers)
29+
STARS[project.title] = stargazers
30+
elif response.status_code == 403:
31+
# gh api rate limited
32+
error_console.log(
33+
"GitHub has received too many requests and started rate limiting."
34+
)
35+
exit(1)
36+
else:
37+
# any other reason
38+
print(
39+
f"GET https://api.github.com/repos/{project.repo_url_part} returned status code {response.status_code}"
40+
)
41+
# replace
42+
with open(
43+
os.path.join(os.path.dirname(__file__), "_project_stars.py"), "w"
44+
) as file:
45+
file.write("STARS = " + json.dumps(STARS, indent=4))
46+
console.log("Done!")
47+
48+
49+
if __name__ == "__main__":
50+
main()

src/textual/demo/_project_stars.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
STARS = {
2+
"Posting": "9.5k",
3+
"Memray": "14.2k",
4+
"Toolong": "3.5k",
5+
"Dolphie": 857,
6+
"Harlequin": "4.8k",
7+
"Elia": "2.2k",
8+
"Trogon": "2.6k",
9+
"TFTUI - The Terraform textual UI": "1.1k",
10+
"RecoverPy": "1.5k",
11+
"Frogmouth": "2.8k",
12+
"oterm": "2.0k",
13+
"logmerger": 194,
14+
"doit": "2.6k",
15+
}

src/textual/demo/projects.py

Lines changed: 12 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,8 @@
88
from textual.containers import Center, Horizontal, ItemGrid, Vertical, VerticalScroll
99
from textual.demo.page import PageScreen
1010
from textual.widgets import Footer, Label, Link, Markdown, Static
11-
12-
13-
@dataclass
14-
class ProjectInfo:
15-
"""Dataclass for storing project information."""
16-
17-
title: str
18-
author: str
19-
url: str
20-
description: str
21-
stars: str
22-
11+
from textual.demo._project_stars import STARS
12+
from textual.demo._project_data import PROJECTS, ProjectInfo
2313

2414
PROJECTS_MD = """\
2515
# Projects
@@ -30,101 +20,6 @@ class ProjectInfo:
3020
See below for a small selection!
3121
"""
3222

33-
PROJECTS = [
34-
ProjectInfo(
35-
"Posting",
36-
"Darren Burns",
37-
"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",
40-
),
41-
ProjectInfo(
42-
"Memray",
43-
"Bloomberg",
44-
"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",
47-
),
48-
ProjectInfo(
49-
"Toolong",
50-
"Will McGugan",
51-
"https://github.com/Textualize/toolong",
52-
"""A terminal application to view, tail, merge, and search log files (plus JSONL).""",
53-
"3.2k",
54-
),
55-
ProjectInfo(
56-
"Dolphie",
57-
"Charles Thompson",
58-
"https://github.com/charles-001/dolphie",
59-
"Your single pane of glass for real-time analytics into MySQL/MariaDB & ProxySQL",
60-
"649",
61-
),
62-
ProjectInfo(
63-
"Harlequin",
64-
"Ted Conbeer",
65-
"https://harlequin.sh/",
66-
"""Portable, powerful, colorful. An easy, fast, and beautiful database client for the terminal.""",
67-
"3.7k",
68-
),
69-
ProjectInfo(
70-
"Elia",
71-
"Darren Burns",
72-
"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",
76-
),
77-
ProjectInfo(
78-
"Trogon",
79-
"Textualize",
80-
"https://github.com/Textualize/trogon",
81-
"Auto-generate friendly terminal user interfaces for command line apps.",
82-
"2.5k",
83-
),
84-
ProjectInfo(
85-
"TFTUI - The Terraform textual UI",
86-
"Ido Avraham",
87-
"https://github.com/idoavrah/terraform-tui",
88-
"TFTUI is a powerful textual UI that empowers users to effortlessly view and interact with their Terraform state.",
89-
"1k",
90-
),
91-
ProjectInfo(
92-
"RecoverPy",
93-
"Pablo Lecolinet",
94-
"https://github.com/PabloLec/RecoverPy",
95-
"""RecoverPy is a powerful tool that leverages your system capabilities to recover lost files.""",
96-
"1.3k",
97-
),
98-
ProjectInfo(
99-
"Frogmouth",
100-
"Dave Pearson",
101-
"https://github.com/Textualize/frogmouth",
102-
"""Frogmouth is a Markdown viewer / browser for your terminal, built with Textual.""",
103-
"2.5k",
104-
),
105-
ProjectInfo(
106-
"oterm",
107-
"Yiorgis Gozadinos",
108-
"https://github.com/ggozad/oterm",
109-
"The text-based terminal client for Ollama.",
110-
"1k",
111-
),
112-
ProjectInfo(
113-
"logmerger",
114-
"Paul McGuire",
115-
"https://github.com/ptmcg/logmerger",
116-
"logmerger is a TUI for viewing a merged display of multiple log files, merged by timestamp.",
117-
"162",
118-
),
119-
ProjectInfo(
120-
"doit",
121-
"Murli Tawari",
122-
"https://github.com/kraanzu/dooit",
123-
"A todo manager that you didn't ask for, but needed!",
124-
"2.1k",
125-
),
126-
]
127-
12823

12924
class Project(Vertical, can_focus=True, can_focus_children=False):
13025
"""Display project information and open repo links."""
@@ -133,16 +28,16 @@ class Project(Vertical, can_focus=True, can_focus_children=False):
13328
DEFAULT_CSS = """
13429
Project {
13530
width: 1fr;
136-
height: auto;
31+
height: auto;
13732
padding: 0 1;
13833
border: tall transparent;
13934
box-sizing: border-box;
140-
&:focus {
35+
&:focus {
14136
border: tall $text-primary;
14237
background: $primary 20%;
14338
&.link {
14439
color: red !important;
145-
}
40+
}
14641
}
14742
#title { text-style: bold; width: 1fr; }
14843
#author { text-style: italic; }
@@ -179,7 +74,7 @@ def compose(self) -> ComposeResult:
17974
info = self.project_info
18075
with Horizontal(classes="header"):
18176
yield Label(info.title, id="title")
182-
yield Label(f"★ {info.stars}", classes="stars")
77+
yield Label(f"★ {STARS[info.title]}", classes="stars")
18378
yield Label(info.author, id="author")
18479
yield Link(info.url, tooltip="Click to open project repository")
18580
yield Static(info.description, classes="description")
@@ -197,18 +92,18 @@ def action_open_repository(self) -> None:
19792
class ProjectsScreen(PageScreen):
19893
AUTO_FOCUS = None
19994
CSS = """
200-
ProjectsScreen {
201-
align-horizontal: center;
95+
ProjectsScreen {
96+
align-horizontal: center;
20297
ItemGrid {
20398
margin: 2 4;
20499
padding: 1 2;
205100
background: $boost;
206101
width: 1fr;
207-
height: auto;
102+
height: auto;
208103
grid-gutter: 1 1;
209-
grid-rows: auto;
210-
keyline:thin $foreground 30%;
211-
}
104+
grid-rows: auto;
105+
keyline:thin $foreground 30%;
106+
}
212107
Markdown { margin: 0; padding: 0 2; max-width: 100; background: transparent; }
213108
}
214109
"""

0 commit comments

Comments
 (0)