-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgvlquery.py
More file actions
271 lines (233 loc) · 9.22 KB
/
gvlquery.py
File metadata and controls
271 lines (233 loc) · 9.22 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#
# gvlquery.py
#
# query the GVL for any thing we are interested in
# query the AVI for any thing we are interested in
#
# argument -v verbose output
#
# Todo:
#
# implement the verbose option
#
import json
import urllib
from urllib.request import urlopen
import datetime
import re
# strGvl = "https://vendor-list.consensu.org/v3/vendor-list.json"
# strAvi = "https://vendor-list.consensu.org/v2/additional-vendor-information-list.json"
strAvi = "https://vendor-list.consensu.org/v2/archives/additional-vendor-information-list-v182.json" # end of 2025
# strGvl = "https://vendor-list.consensu.org/v2/archives/vendor-list-v81.json" # use to test the tcfapi tests
strGvl = "https://vendor-list.consensu.org/v3/archives/vendor-list-v139.json" # end of 2025
gvlf = urlopen(strGvl).read()
dictGvl = json.loads(gvlf)
dictVendors = dictGvl['vendors']
deletedVendorIds = []
# Print the current date and time
print("Date queries for GVL...")
print("Date and time:", datetime.datetime.now())
# return the header info and total number of vendors in the GVL
print("File used:", strGvl.rsplit('/', 1)[1])
print("gvlSpecificationVersion:", dictGvl['gvlSpecificationVersion'])
print("vendorListVersion:", dictGvl['vendorListVersion'])
print("lastUpdated:", dictGvl['lastUpdated'])
print("Total numbers of vendors:", len(dictVendors))
cnt = 0
for x in dictVendors:
if 'deletedDate' in dictVendors[x]:
deletedVendorIds.append(dictVendors[x]['id'])
cnt += 1
# print("Debug: ", deletedVendorIds, " ", len(deletedVendorIds))
print("Total operational vendors:", len(dictVendors) - cnt)
# cnt = 0
# for x in dictVendors:
# if len(dictVendors[x]['purposes']) == 0 and len(dictVendors[x]['legIntPurposes']) == 0 and len(dictVendors[x]['specialPurposes']) > 0:
# cnt += 1
# print("id: " + x + " name: " + dictVendors[x]['name'])
# print("Total with special purposes only: ", cnt)
# The number of Vendors that have declared at least one purpose based on LI + at least one SP
# (those will still have ambiguity in their signalling after the update)
# cnt = 0
# for x in dictVendors:
# if 'deletedDate' not in dictVendors[x] and len(dictVendors[x]['legIntPurposes']) > 0 and len(dictVendors[x]['specialPurposes']) > 0:
# cnt += 1
# print("id: " + x + " name: " + dictVendors[x]['name'])
# print("Total with LI and special purposes: ", cnt)
# The number of Vendors that have declared at least one purpose based on LI + at least one SP
# but no consent purpose (those will still have ambiguity in their signalling after the update)
# cnt = 0
# for x in dictVendors:
# if 'deletedDate' not in dictVendors[x] and len(dictVendors[x]['purposes']) == 0 and len(dictVendors[x]['legIntPurposes']) > 0 and len(dictVendors[x]['specialPurposes']) > 0:
# cnt += 1
# print("id: " + x + " name: " + dictVendors[x]['name'])
# print("Total with LI and special purposes but no purpose consent: ", cnt)
# the number of Vendors that have declared only purposes based on consent (no LI) + at least one SP
# (those will have the signalling ambiguity removed with the upcoming update to the library)
# cnt = 0
# for x in dictVendors:
# if 'deletedDate' not in dictVendors[x] and len(dictVendors[x]['purposes']) > 0 and len(dictVendors[x]['legIntPurposes']) == 0 and len(dictVendors[x]['specialPurposes']) > 0:
# cnt += 1
# print("id: " + x + " name: " + dictVendors[x]['name'])
# print("Total with only purposes consent and special purposes: ", cnt)
# the number of Vendors that have declared at least one SP
# cnt = 0
# for x in dictVendors:
# if 'deletedDate' not in dictVendors[x] and len(dictVendors[x]['specialPurposes']) > 0:
# cnt += 1
# print("id: " + x + " name: " + dictVendors[x]['name'])
# print("Total with special purposes: ", cnt)
#
# returns the number of vendors per purpose
#
def find_element(arr, target):
try:
return arr.index(target)
except ValueError:
return -1
print("***Number of vendors per purpose: ")
def num_vendors_per_purpose(purpose_no):
cnt = 0
for x in dictVendors:
if 'deletedDate' not in dictVendors[x] and len(dictVendors[x]['purposes']) != 0 and find_element(dictVendors[x]['purposes'], purpose_no) != -1:
cnt += 1
print("Vendors with purpose " + str(purpose_no) + ": " + str(cnt))
for x in range(1, 12):
num_vendors_per_purpose(x)
print("***Done with number of purposes by vendor")
#
# returns the number of vendors not using purpse 2,3,4 and 7
#
cnt = 0
for x in dictVendors:
if 'deletedDate' not in dictVendors[x] and len(dictVendors[x]['purposes']) != 0 \
and find_element(dictVendors[x]['purposes'], 2) == -1 \
and find_element(dictVendors[x]['purposes'], 3) == -1 \
and find_element(dictVendors[x]['purposes'], 4) == -1 \
and find_element(dictVendors[x]['purposes'], 7) == -1:
cnt += 1
for x in dictVendors:
if len(dictVendors[x]['purposes']) == 0:
cnt += 1
print("***Vendors that have not declared either Purpose 2,3,4 and 7: " + str(cnt))
#
# number of vendor and names of vendors that only declare SP (no purposed neiter consent nor LI)
#
# the number of Vendors that have declared at least one SP
cnt = 0
print("***Vendor only declaring SPs")
for x in dictVendors:
if 'deletedDate' not in dictVendors[x] and len(dictVendors[x]['specialPurposes']) > 0 \
and len(dictVendors[x]['purposes']) == 0 and len(dictVendors[x]['legIntPurposes']) == 0:
cnt += 1
print("id: " + x + " name: " + dictVendors[x]['name'] + " '" + str(dictVendors[x]['purposes']) + "'" + " '" + str(dictVendors[x]['legIntPurposes']) + "'" + " '" + str(dictVendors[x]['specialPurposes']) + "'")
print("Total with special purposes: ", cnt)
print("Done with GVL data.")
# Debug: to stop the script here
# exit(0)
#
#
# query somethings from the AVI JSON file
#
avif = urlopen(strAvi).read()
dictAvi = json.loads(avif)
dictAviVendors = dictAvi['vendors']
print("\n")
print("Date queries for AVI...")
print("Date and time:", datetime.datetime.now())
# return the header info and total number of vendors in the AVI
str = "aviSpecificationVersion:"
print(f"{str:<28} {dictAvi['aviSpecificationVersion']}")
str = "aviSpecificationVersion:"
print(f"{str:<28} {dictAvi['aviSpecificationVersion']}")
str = "aviListVersion:"
print(f"{str:<28} {dictAvi['aviListVersion']}")
str = "Total numbers of vendors:"
print(f"{str:<28} {len(dictAviVendors)}")
unclassifiedList = []
dictCountry = { "GERMANY" : 0 }
cnt = 0
for x in dictAviVendors:
if dictAviVendors[x]['id'] in deletedVendorIds:
continue
addrStr = dictAviVendors[x]['legalAddress']
addrList = addrStr.rsplit(';')
i = len(addrList)
cStr = addrList[i - 1]
cStr = cStr.upper()
cStr = cStr.rstrip(" ") # remove trailing spaces
# check for spelling error and know variations and fix these
if cStr == "UNITED KINDOM" or cStr == "UNITED KINGDON" or cStr == "UNITED KINGOM" or cStr == "ENGLAND" or cStr == "GREAT BRITAIN" or cStr == "LONDON":
cStr = "UNITED KINGDOM"
elif cStr == "USA" or cStr == "UNITED STATE" or cStr == "THE USA" or cStr == "UNITED STATES OF AMERICA":
cStr = "UNITED STATES"
elif cStr == "THE NETHERLANDS" or cStr == "NEDERLAND":
cStr = "NETHERLANDS"
elif cStr == "TURKIYE" or cStr == "TÜRKIYE":
cStr = "TURKEY"
elif cStr == "VEINNA" or cStr == "VIENA" or cStr == "VIENNA":
cStr = "AUSTRIA"
elif cStr == "DANMARK":
cStr = "DENMARK"
elif cStr == "DÜSSELDORF" or cStr == "MÜNCHEN" or cStr == "NÜRNBERG" or cStr == "GERMANDY" or cStr == "HAMBORG":
cStr = "GERMANY"
elif cStr == "ITALIA":
cStr = "ITALY"
elif cStr == "SLOVENIJA":
cStr = "SLOVENIA"
elif cStr == "SCHWEIZ":
cStr = "SWITZERLAND"
elif cStr == "ESPAÑA":
cStr = "SPAIN"
elif cStr == "BRAZIL":
cStr = "BRASIL"
elif cStr == "PARIS":
cStr = "FRANCE"
elif re.search("[0-9]", cStr):
unclassifiedList.append(cStr)
cStr = "Z_UNCLASSIFIED"
myList = list(dictCountry.keys())
try:
y = myList.index(cStr)
cnt = dictCountry.get(cStr)
cnt += 1
dictCountry.update({cStr: cnt})
except ValueError:
# add the new string to the dictionary
dictCountry.update({cStr: 1})
## output the country listing:
print("List of Countries:")
sorted_dict = dict(sorted(dictCountry.items(), key=lambda item: item[0]))
cCnt = 0
for x in sorted_dict:
print(f"{x:<24} {sorted_dict[x]}")
cCnt += sorted_dict[x]
str = "Total entries found:"
print(f"{str:<24} {cCnt}")
## output the unclassified list:
outStr = ""
for x in unclassifiedList:
outStr += x
outStr += ', '
print("Z_UNCLASSIFIED:", outStr.rstrip(", "))
# operating environments
cntWeb = 0
cntMobile = 0
cntCTV = 0
for x in dictAviVendors:
if dictAviVendors[x]['id'] in deletedVendorIds:
continue
for y in dictAviVendors[x]['environments']:
if y == 'Web':
cntWeb += 1
if y == 'Native App (Mobile)':
cntMobile += 1
if y == 'Native App (CTV)':
cntCTV += 1
str = "Vendor operating on Web:"
print(f"{str:<28} {cntWeb}")
str = "Vendor operating on Mobile:"
print(f"{str:<28} {cntMobile}")
str = "Vendor operating on CTV:"
print(f"{str:<28} {cntCTV}")
print("Done with AVI data.")