-
Notifications
You must be signed in to change notification settings - Fork 8
/
pull_stats.py
executable file
·40 lines (31 loc) · 1.13 KB
/
pull_stats.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
#!/usr/bin/env python3
import os
import subprocess
import json
import shutil
if subprocess.call(["wget", "--execute", "robots=off", "--recursive", "--no-host-directories", "--no-parent", "--reject-regex", "backup", "--accept", "*.json", "https://flathub.org/stats/"]) != 0:
exit(1)
files = []
refs = {}
for (dirpath, _, filenames) in os.walk("stats"):
files.extend(os.path.join(dirpath, filename) for filename in filenames)
files.sort()
# The latest stats aren't very accurate, please see: https://github.com/klausenbusk/flathub-stats/issues/5
del files[-1]
for f in files:
print(f)
with open(f) as json_file:
data = json.load(json_file)
date = data["date"]
for ref in data["refs"]:
refs.setdefault(ref, {"ref": ref, "stats": []})["stats"].append({"date": date, "arches": data["refs"][ref]})
os.chdir("web")
if os.path.isdir("data"):
shutil.rmtree("data")
os.mkdir("data")
def writeJson(f, data):
with open(f, "w") as outfile:
json.dump(data, outfile)
for ref in refs:
writeJson(f"data/{ref.replace('/', '_')}.json", refs[ref])
writeJson("data/refs.json", list(refs.keys()))