-
Notifications
You must be signed in to change notification settings - Fork 7
/
identify_vendor.py
67 lines (57 loc) · 2.13 KB
/
identify_vendor.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import os
from utils import *
class Webxray_database:
def __init__(self):
self.companies = json.load(open(os.path.dirname(os.path.abspath(__file__)) + '/webxray_resources/domain_owners_grouped.json', 'r', encoding='utf-8'))
def get_all_names_from_domain(self, domain):
for company in self.companies:
if domain in company["domains"]:
return set(company["names"])
return set()
class Disconnect_database:
def __init__(self):
self.companies = {}
self.domains = set()
self.domain_to_name = {}
entities = json.load(open(os.path.dirname(os.path.abspath(__file__)) + '/disconnect_resources/entities.json', 'r', encoding='utf-8'))
for e in entities:
self.companies[e] = set()
for url in entities[e]["properties"]:
self.companies[e].add(url)
self.domains.add(url)
self.domain_to_name[url] = e
for url in entities[e]["resources"]:
self.companies[e].add(url)
self.domains.add(url)
self.domain_to_name[url] = e
def is_tracker(self, domain):
return domain in self.domains
def get_name_from_domain(self, domain):
try:
return self.domain_to_name[domain]
except KeyError:
return None
class Vendorlist_database:
# Extract domain from privacy policy URL
def __init__(self, vendorlist):
psl = publicsuffix2.fetch()
self.domain_to_id = {}
self.id_to_vendor = {}
for vendor in vendorlist["vendors"]:
# get privacy policy domain
domain = url_to_domain(vendor["policyUrl"], psl)
self.domain_to_id[domain] = vendor["id"]
self.id_to_vendor[vendor["id"]] = vendor
def get_id_from_domain(self, domain):
try:
return self.domain_to_id[domain]
except KeyError:
return None
def get_vendor(self, vendor_id):
try:
return self.id_to_vendor[vendor_id]
except KeyError:
return None