This repository was archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrun.py
More file actions
42 lines (36 loc) · 1.31 KB
/
run.py
File metadata and controls
42 lines (36 loc) · 1.31 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
import os
import sys
from git import Repo
from datetime import datetime, timezone, timedelta
from risklevel import main as risklevel_main
ABS_PATH = os.path.dirname(os.path.abspath(__file__))
API_PATH = os.path.join(ABS_PATH, 'Archive')
if len(sys.argv) == 2 and sys.argv[1] == 'init':
clone_path = input('Input the remote repository path: ')
print('Cloning...')
repo = Repo.clone_from(clone_path, API_PATH)
repo.git.checkout('api')
repo.git.pull()
print('API folder initialized')
print('Run `python3 run.py` to start fetching data')
sys.exit(0)
if not os.path.exists(API_PATH):
print('API folder not found.')
print('Run `python3 run.py init` to initialize the API folder.')
sys.exit(1)
repo = Repo(API_PATH)
repo.git.pull()
assert os.path.exists(os.path.join(API_PATH, 'latest.json'))
fetch_result = risklevel_main()
# get commit message as "Update at Sat Aug 13 22:29:33 CST 2022"
current_time = datetime.now(tz=timezone(timedelta(hours=8))).strftime("%a %b %d %H:%M:%S %z %Y")
current_time = current_time.replace('+0800', 'CST')
if fetch_result:
repo.git.add(all=True)
commit_msg = f'Update at {current_time}'
print(commit_msg)
repo.git.commit('-m', commit_msg)
repo.git.push()
print('Update successful')
else:
print(f'No update needed at {current_time}')