This repository has been archived by the owner on Feb 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_app_data.py
83 lines (69 loc) · 1.84 KB
/
cache_app_data.py
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
#!/usr/bin/env python
import os
import json
import tempfile
import subprocess
import requests
# first pull down the data
latest_data = requests.get(
"https://cf-action-counter.herokuapp.com/db").json()
# run git config
subprocess.run(
"git config --global user.email '[email protected]'",
shell=True,
check=True,
)
subprocess.run(
"git config --global user.name 'circle worker'",
shell=True,
check=True,
)
# now update the repo
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
subprocess.run(
("git clone --depth=1 "
"https://github.com/regro/cf-action-counter-db.git"),
shell=True,
check=True,
)
os.chdir("cf-action-counter-db")
os.makedirs("data", exist_ok=True)
if os.path.exists("data/latest.json"):
with open("data/latest.json", "r") as fp:
old_data = json.load(fp)
back_stamp = list(old_data["github-actions"]["rates"].keys())[-1]
back_pth = "data/data_%s.json" % back_stamp
with open(back_pth, "w") as fp:
json.dump(old_data, fp)
subprocess.run(
"git add %s" % back_pth,
shell=True,
check=True,
)
with open("data/latest.json", "w") as fp:
json.dump(latest_data, fp)
subprocess.run(
["git add data/latest.json"],
shell=True,
check=True,
)
stat = subprocess.run(
["git status"],
shell=True,
check=True,
capture_output=True,
)
status = stat.stdout.decode('utf-8')
print(status)
if "nothing to commit" not in status:
subprocess.run(
["git commit -m 'hourly data update'"],
shell=True,
check=True,
)
subprocess.run(
["git push"],
shell=True,
check=True,
)