-
Notifications
You must be signed in to change notification settings - Fork 2
/
unlicensed_images.py
77 lines (63 loc) · 2.07 KB
/
unlicensed_images.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
68
69
70
71
72
73
74
75
76
77
from utils import time_and_date
from wikitools import wiki
from wikitools.page import Page
verbose = False
def main(w):
image_templates = [
'ScreenshotTF2',
'AudioTF2',
'ArtworkTF2',
'ExtractTF2',
'Valve content',
'TFC image',
'ArtworkTF2-Pre',
'PD',
'QTF image',
'PD-self',
'Fairuse',
'CC',
'L4D image',
'FAL',
'GDFL',
'GPL',
'LGPL',
]
all_files = {}
for file in w.get_all_pages(namespaces = ['File']):
all_files[file] = []
if verbose:
print(f'Found {len(all_files)} files')
non_files_with_transclusions = []
for template in image_templates:
for file in Page(w, f'Template:{template}').get_transclusions(namespaces=['*']):
if file not in all_files:
non_files_with_transclusions.append(file)
all_files[file] = [template]
else:
all_files[file].append(template)
if verbose:
print('Processed all templates')
files_with_multiple_templates = [file for file, templates in all_files.items() if len(templates) > 1]
files_with_no_template = [file for file, templates in all_files.items() if len(templates) == 0]
output = """\
{{{{DISPLAYTITLE: {count} files with incorrect licensing}}}}
Found '''<onlyinclude>{count}</onlyinclude>''' files which have an incorrect licensing. Data as of {date}.
""".format(
count=len(non_files_with_transclusions) + len(files_with_multiple_templates) + len(files_with_no_template),
date=time_and_date())
output += '== Non-files with file license templates ==\n'
for page in non_files_with_transclusions:
output += f'* [[:{page}]]\n'
output += '== Files with >1 license template ==\n'
for file in files_with_multiple_templates:
output += f'* [[:{file}]]\n'
output += '== Files with no license templates ==\n'
for file in files_with_no_template:
output += f'* [[:{file}]]\n'
return output
if __name__ == '__main__':
verbose = True
w = wiki.Wiki('https://wiki.teamfortress.com/w/api.php')
with open('wiki_unlicensed_images.txt', 'w') as f:
f.write(main(w))
print(f'Article written to {f.name}')