-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotebook.py
More file actions
126 lines (103 loc) · 3.39 KB
/
notebook.py
File metadata and controls
126 lines (103 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import marimo
__generated_with = "0.11.8"
app = marimo.App(app_title="", css_file="")
@app.cell
def _():
"""
Export to WASM-powered HTML:
uv run marimo export html-wasm notebook.py -o . --mode run
Serve locally:
uv run -m http.server --directory .
"""
from itertools import cycle
from urllib.parse import urlencode
import marimo as mo
with mo.status.spinner("loading snakes on a browser..."):
# import micropip
# await micropip.install('requests')
import requests
# get and set login name from query param
# if _no_ login param, then login is eidorb
# otherwise login is set to login param
# if login param _present_ but empty,
# app will be in an "uninitialised" state
query_params = mo.query_params()
login = mo.ui.text(
value="eidorb"
if query_params["login"] is None #
else query_params["login"],
on_change=lambda value: query_params.set("login", value),
)
return cycle, login, mo, query_params, requests, urlencode
@app.cell
def _(avatar_url, login, mo, query_params, urlencode):
mo.md(
f"""
/// details | {
mo.image(
avatar_url,
width=123,
rounded=True,
caption=f"{login.value}'s projects" if login.value else None,
).center()
}
This webpage is interactive!
Enter your GitHub login: {login}
/// admonition | Come again
Changing the login updates this page's URL.
Use it to come back to the same state:
{
mo.ui.text(
f"{str(mo.notebook_location())}?{urlencode(query_params.to_dict())}",
full_width=True,
)
}
///
///
"""
)
return
@app.cell
def _(cycle, login, mo, requests):
# get avatar or placeholder if user not found :(
try:
with mo.status.spinner():
response = requests.get(f"https://api.github.com/users/{login.value}")
response.raise_for_status()
user = response.json()
repos = requests.get(user["repos_url"]).json()
avatar_url = user["avatar_url"]
except requests.HTTPError:
user = None
avatar_url = (
"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
)
# filter my repos: not forks; have a homepage link
if user:
projects = [
repo
for repo in repos
if not repo["fork"] and repo["homepage"] and repo["name"] != "eidorb.github.io"
]
# no user has no repos
else:
projects = []
# use differnt types of details to style with colour
for repo, type in zip(projects, cycle(["info", "warn", "danger", "success"])):
mo.output.append(
mo.md(
f"""
/// details | [{repo["name"]}]({repo["homepage"]})
type: {type}
{repo["description"]} [::line-md:github-loop::]({repo["html_url"]})
///
"""
)
)
return avatar_url, projects, repo, repos, response, type, user
@app.cell
def _(mo):
mo.md(r"""<small>Hack on your own copy of this notebook [here](https://marimo.app/https://eidorb.github.io/notebook.py).</small>""")
return
if __name__ == "__main__":
app.run()