forked from nikgapps/build
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalytics_control.py
89 lines (81 loc) · 3.46 KB
/
analytics_control.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
84
85
86
87
88
89
import json
import os
from pathlib import Path
import Config
from NikGapps.Helper import C, FileOp, Git, Logs
repo_name = "[email protected]:nikgapps/config.git"
repo_dir = C.pwd + C.dir_sep + "config"
branch = "main"
analytics_dict = {}
custom_build_dict = {}
print()
print("Repo Dir: " + repo_dir)
todays_custom_builds_count = 0
config_repo = Git(repo_dir)
config_repo.clone_repo(repo_name)
if FileOp.dir_exists(repo_dir):
print(f"{repo_dir} exists!")
archive_dir = repo_dir + C.dir_sep + "archive"
directory_contents = os.listdir(archive_dir)
print(directory_contents)
todays_date = str(Logs.get_current_time())
for directory in directory_contents:
android_version_dir = archive_dir + C.dir_sep + str(directory)
count = 0
for pkg_files in Path(android_version_dir).rglob("*"):
if Path(pkg_files).is_file():
count += 1
analytics_dict[directory] = count
android_version_dir_today = android_version_dir + C.dir_sep + todays_date
for pkg_files in Path(android_version_dir_today).rglob("*"):
if Path(pkg_files).is_file():
todays_custom_builds_count += 1
custom_build_dict[todays_date] = todays_custom_builds_count
else:
print(f"{repo_dir} doesn't exist!")
print("Download count from archive directory: " + str(analytics_dict))
print("Today's Download count so far: " + str(custom_build_dict))
repo_name = "[email protected]:nikgapps/tracker.git"
repo_dir = C.pwd + C.dir_sep + "tracker"
print()
print("Repo Dir: " + repo_dir)
tracker_repo = Git(repo_dir)
tracker_repo.clone_repo(repo_name)
if FileOp.dir_exists(repo_dir):
print(f"{repo_dir} exists!")
custom_builds_count_json = repo_dir + C.dir_sep + "count.json"
if FileOp.file_exists(custom_builds_count_json):
print("File Exists!")
custom_builds_json_string = ""
for line in FileOp.read_string_file(custom_builds_count_json):
custom_builds_json_string += line
print(custom_builds_json_string)
print()
decoded_hand = json.loads(custom_builds_json_string)
total_count = 0
for key in analytics_dict:
key_code = Config.ANDROID_VERSIONS[key]["code"]
print(f"Update download count for {key}({key_code})")
if decoded_hand.get(key_code) is not None:
# get the download count of the key
download_count_before = decoded_hand[key_code]
decoded_hand[key_code] = str(analytics_dict[key])
print(f"Download count for {key} updated from {download_count_before} to {str(analytics_dict[key])}")
else:
print(f"key doesn't exist.. so creating {str(analytics_dict[key])}")
decoded_hand[key_code] = str(analytics_dict[key])
total_count += int(decoded_hand[key_code])
print()
decoded_hand['total'] = str(total_count)
print(decoded_hand)
with open(custom_builds_count_json, "w") as file:
json.dump(decoded_hand, file, indent=2, sort_keys=True)
try:
print("Updating the download count in tracker repository")
print("Custom builds so far created today: " + str(todays_custom_builds_count))
tracker_repo = Git(repo_dir)
tracker_repo.update_repo_changes("Custom builds so far created today: " + str(todays_custom_builds_count))
except Exception as e:
print(str(e))
else:
print(f"{repo_dir} doesn't exist!")