-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (37 loc) · 1.32 KB
/
main.py
File metadata and controls
48 lines (37 loc) · 1.32 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
import asyncio
import os
import yaml
from src.services.github_api import get_all_traffic_data, get_profile_name
from src.services.chart_generator import generate_chart
GITHUB_USERNAME = os.getenv("GITHUB_USERNAME")
traffic_data_lock = asyncio.Lock()
def load_config():
with open("config.yml", "r", encoding="utf-8") as f:
return yaml.safe_load(f)
async def generate_new_data():
print("Fetching GitHub traffic data...")
async with traffic_data_lock:
traffic_results, profile_name = await asyncio.gather(
get_all_traffic_data(GITHUB_USERNAME),
get_profile_name()
)
return traffic_results, profile_name
async def main():
try:
config = load_config()
traffic_results, profile_name = await generate_new_data()
chart_params = {
"profile_name": profile_name,
"traffic_results": traffic_results,
**config
}
print("Generating chart...")
chart_svg = generate_chart(**chart_params)
os.makedirs("generated", exist_ok=True)
with open("generated/traffic_chart.svg", "w", encoding="utf-8") as f:
f.write(chart_svg)
print(f"SVG saved finished!")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
asyncio.run(main())