-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.py
52 lines (41 loc) · 1.85 KB
/
update.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
#!/bin/python3
import json
import os
import requests
entities_link = "https://raw.githubusercontent.com/disconnectme/disconnect-tracking-protection/master/entities.json"
services_link = "https://raw.githubusercontent.com/disconnectme/disconnect-tracking-protection/master/services.json"
def retrieve_contents(link):
response = requests.get(link)
return response.content
def generate_entities_files():
content = retrieve_contents(entities_link)
entities = json.loads(content)["entities"]
domains = set()
for entity in entities.values():
for domain in entity["resources"]:
domain = domain.split('/')[0].strip() # strip out path from domain
domains.add(domain)
with open("entities.txt", "w") as f:
for domain in sorted(domains):
print(domain, file=f)
def generate_services_files():
content = retrieve_contents(services_link)
categories = json.loads(content)["categories"]
category_domains = {}
for category, services in categories.items():
for service in services:
for domains in service.values():
for domain_list in domains.values():
if isinstance(domain_list, list):
domain_list = [domain.split('/')[0] for domain in domain_list] # strip out path from domain
category_domains.setdefault(category, set()).update(domain_list)
with open("services.txt", "w") as f:
for category, domains in sorted(category_domains.items()):
for domain in sorted(domains):
print(domain, file=f)
for category, domains in sorted(category_domains.items()):
with open(f"services_{category}.txt", "w") as f_category:
for domain in sorted(domains):
print(domain, file=f_category)
generate_entities_files()
generate_services_files()