-
Notifications
You must be signed in to change notification settings - Fork 10
/
append.py
executable file
·44 lines (37 loc) · 1.17 KB
/
append.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
#!/usr/bin/env python3
# Copyright 2021 Erfan Abdi
# SPDX-License-Identifier: GPL-3.0-or-later
import json
import argparse
import os
# Instantiate the parser
parser = argparse.ArgumentParser(description='OTA JSON Data appender')
# Required positional argument
parser.add_argument('JSON_FILE')
parser.add_argument('TIMESTAMP')
parser.add_argument('ZIP_NAME')
parser.add_argument('ZIP_SHA')
parser.add_argument('BUILD_TYPE')
parser.add_argument('ZIP_SIZE')
parser.add_argument('ZIP_URL')
parser.add_argument('ROM_VERSION')
args = parser.parse_args()
new_ota = {
"datetime": int(args.TIMESTAMP),
"filename": args.ZIP_NAME,
"id": args.ZIP_SHA,
"romtype": args.BUILD_TYPE,
"size": int(args.ZIP_SIZE),
"url": args.ZIP_URL,
"version": args.ROM_VERSION
}
if not os.path.exists(args.JSON_FILE):
with open(args.JSON_FILE, 'w') as f:
data = {"response": []}
f.write(json.dumps(data, indent=4))
with open(args.JSON_FILE, 'r+') as file:
file_data = json.load(file)
file_data["response"].insert(0, new_ota)
file.seek(0)
json.dump(file_data, file, indent=4)
print("Done")