-
Notifications
You must be signed in to change notification settings - Fork 73
/
data.py
30 lines (26 loc) · 1.23 KB
/
data.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
import json
from pathlib import Path
from whotracksme.data.db import load_tracker_db, create_tracker_map
from whotracksme.website.utils import print_progress
def build_tracker_db():
with open('_site/data/trackerdb.json', 'w') as output:
db_map = create_tracker_map(load_tracker_db(), with_iab_vendors=True)
db_map['about'] = 'WhoTracks.Me tracker database: whotracks.me'
json.dump(db_map, output, indent=2, sort_keys=True)
print_progress(text='Generate tracker DB')
def build_api(data):
# tracker overviews
data_dir = Path('_site/data/trackers/global')
if not data_dir.exists():
data_dir.mkdir(parents=True)
for id, stats in data.trackers.iter():
stats = data.trackers.get_tracker(id)
stats['overview'] = dict(stats['overview'])
# drop some columns
for col in ['Index', 'companies', 'month', 'trackers', 'tracker', 'id', 'company_id', 'category', 'country']:
del stats['overview'][col]
stats['date_range'] = [date.strftime('%Y-%m') for date in stats['date_range']]
# print(stats)
with open(f'_site/data/trackers/global/{id}.json', 'w') as output:
json.dump(stats, output)
print_progress(text='Generate API data')