-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_engine.py
More file actions
39 lines (25 loc) · 822 Bytes
/
export_engine.py
File metadata and controls
39 lines (25 loc) · 822 Bytes
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
from github import Github
from config import GITHUB_TOKEN, GITHUB_REPO, GITHUB_BRANCH
FILES = {
"daily": "daily.txt",
"achievements": "achievements.txt",
"failures": "failures.txt",
}
def fetch_file_content(file_name):
g = Github(GITHUB_TOKEN)
repo = g.get_repo(GITHUB_REPO)
try:
file = repo.get_contents(file_name, ref=GITHUB_BRANCH)
return file.decoded_content.decode()
except Exception:
return "No data available yet."
def export_data(category):
if category == "all":
combined = ""
for name in FILES.values():
combined += f"\n===== {name.upper()} =====\n"
combined += fetch_file_content(name)
return combined
if category in FILES:
return fetch_file_content(FILES[category])
return None