aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Hjortshoej <fyoucon@gmail.com>2020-04-11 21:01:41 +0200
committerMikkel Hjortshoej <fyoucon@gmail.com>2020-04-11 21:01:41 +0200
commit9b9a4fcf22929e2008f54b4cbd03dc04045c4eac (patch)
treeb51c96f0699a3ca7502f9307ec6e4aca936b4089
parenta615402d7c079c188a7e3fa3f4f59428aa52511c (diff)
Python script for creating json
-rw-r--r--ci/create_nightly_json.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/ci/create_nightly_json.py b/ci/create_nightly_json.py
new file mode 100644
index 000000000..4baffe365
--- /dev/null
+++ b/ci/create_nightly_json.py
@@ -0,0 +1,46 @@
+import subprocess
+import sys
+import json
+import datetime;
+
+def main():
+ files_by_date = {}
+
+ files_lines = execute_cli("b2 ls --long odin-binaries nightly").split("\n")
+ for x in files_lines:
+ parts = x.split(" ", 1)
+ if parts[0]:
+ json_str = execute_cli(f"b2 get-file-info {parts[0]}")
+ data = json.loads(json_str)
+ url = execute_cli(f"b2 make-url {data['fileId']}").strip()
+ sha1 = data['contentSha1']
+ name = remove_prefix(data['fileName'], "nightly/")
+ ts = int(data['fileInfo']['src_last_modified_millis'])
+ date = datetime.datetime.fromtimestamp(ts/1000).strftime('%Y-%m-%d')
+
+ if date not in files_by_date.keys():
+ files_by_date[date] = []
+
+ files_by_date[date].append({
+ 'name': name,
+ 'url': url,
+ 'sha1': sha1,
+ })
+
+ now = datetime.datetime.utcnow().isoformat()
+
+ print(json.dumps({
+ 'last_updated' : now,
+ 'files': files_by_date
+ }, sort_keys=True, indent=4))
+
+def remove_prefix(text, prefix):
+ return text[text.startswith(prefix) and len(prefix):]
+
+def execute_cli(command):
+ sb = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
+ return sb.stdout.read().decode("utf-8");
+
+if __name__ == '__main__':
+ sys.exit(main())
+