-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral_stats.py
65 lines (52 loc) · 2.03 KB
/
general_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
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
import os
from util.common import get_server_info, call_to_hdx_with_recorded_time
# URL = 'https://data.humdata.local/api/3/action/hdx_push_general_stats'
ACTION_NAME = 'hdx_push_general_stats'
FILENAME = 'times_general_stats.csv'
CSV_HEADERS = [
'DATASETS TOTAL',
'DATASETS IN QA',
'DATASETS QA COMPLETED',
'DATASETS WITH QUARANTINE',
'DATASETS WITH NO QUARANTINE',
'ORGS TOTAL',
'ORGS WITH DATASETS',
'ORGS UPDATING DATA IN PAST YEAR',
]
def start_process(url: str, is_prod: bool):
token = os.environ.get('HDX_API_TOKEN')
headers = {
'Authorization': token,
'User-Agent': 'HDXINTERNAL_STATS_TRIGGER',
'content-type': 'application/json'
}
call_to_hdx_with_recorded_time(url, headers, {}, FILENAME, f'URL: {url}')
# if result['success']:
# with open(filename, 'a', newline='') as out:
# stats = result['result']['mixpanel_meta']
# writer = csv.writer(out)
# data = [
# stats.get('datasets total'),
# stats.get('datasets in qa'),
# stats.get('datasets qa completed'),
# stats.get('datasets with quarantine'),
# stats.get('datasets with no quarantine'),
# stats.get('orgs total'),
# stats.get('orgs with datasets'),
# stats.get('orgs updating data in past year'),
# ]
# writer.writerow(data)
# print('Finished adding row')
# def create_file_if_necessary(filename):
# if not os.path.isfile(filename):
# with open(filename, 'w', newline='') as out:
# writer = csv.writer(out)
# writer.writerow(CSV_HEADERS)
# print('CSV file created')
# class NoDataException(Exception):
# def __init__(self, message, errors=None):
# super().__init__(message)
# self.errors = errors
if __name__ == '__main__':
base_url, is_prod = get_server_info()
start_process(base_url + ACTION_NAME, is_prod)