-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwiki_duplicate_files.py
More file actions
44 lines (35 loc) · 1.1 KB
/
wiki_duplicate_files.py
File metadata and controls
44 lines (35 loc) · 1.1 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
# -*- coding: utf-8 -*-
import wikitools
WIKI_API = 'http://wiki.tf2.com/w/api.php'
wiki = wikitools.Wiki(WIKI_API)
def get_images(wiki):
params = {'action': 'query',
'generator': 'allimages',
'prop': 'duplicatefiles',
'gailimit': 500
}
req = wikitools.api.APIRequest(wiki, params)
res = req.query(querycontinue=True)
return res['query']['pages']
images = get_images(wiki)
seen = []
dupes = {}
for _image in images:
image = images[_image]
filename = image['title'].replace('_', ' ')
if 'duplicatefiles' in image and filename not in seen:
dupefiles = ['File:'+_file['name'].replace('_', ' ') for _file in image['duplicatefiles']]
for _file in dupefiles:
if _file not in seen:
seen.append(_file)
dupes[filename] = dupefiles
seen.append(filename)
output = ''
for dupe in sorted(dupes):
output += '<gallery>\n'
output += '{0}|{1}\n'.format(dupe, dupe[5:])
for duplicate in dupes[dupe]:
output += '{0}|{1}\n'.format(duplicate, duplicate[5:])
output += '</gallery>\n'
with open('wiki_dupe_files_output.txt', 'wb') as f:
f.write(output)