-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathshortdesc_generator.py
More file actions
71 lines (58 loc) · 1.85 KB
/
Copy pathshortdesc_generator.py
File metadata and controls
71 lines (58 loc) · 1.85 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
# !/usr/bin/python
# -*- coding: utf-8 -*-
# Test of generation of short descriptions
# Mike Peel 08-Aug-2020 v1 - start
import pywikibot
from pywikibot import pagegenerators
from pywikibot.data import api
from wir_newpages import *
def get_pageinfo(site, itemtitle):
params = { 'action' :'query',
'format' : 'json',
'prop' : 'pageprops',
'titles': itemtitle}
request = api.Request(site=site, parameters=params)
return request.submit()
maxnum = 100
nummodified = 0
debug = True
trip = True
wikipedia = pywikibot.Site('en', 'wikipedia')
targetcat = 'Category:English footballers'
cat = pywikibot.Category(wikipedia, targetcat)
count = 0
for page in pagegenerators.CategorizedPageGenerator(cat, recurse=False):
enwiki_description = ''
count += 1
if not trip:
if "Varanasi" in page.title():
trip = True
else:
continue
# Get the short description from enwp
test = get_pageinfo(wikipedia,page)
for item in test['query']['pages']:
try:
enwiki_description = test['query']['pages'][item]['pageprops']['wikibase-shortdesc']
except:
null = 0
if len(enwiki_description) > 0:
print('* [['+page.title()+']] - EXISTS: ' + enwiki_description)
else:
if 'nfobox' not in page.text:
print('* [['+page.title()+"]] - '''NO INFOBOX'''")
else:
enwiki_description = 'English footballer'
birthdate = calculateBirthDate(page=page,lang='en')
deathdate = calculateDeathDate(page=page,lang='en')
if birthdate and deathdate:
enwiki_description += ' (' + str(birthdate[0:4]) + "-" + str(deathdate[0:4]) + ')'
elif birthdate:
enwiki_description += ' (b. ' + str(birthdate[0:4]) + ')'
elif deathdate:
enwiki_description += ' (d. ' + str(birthdate[0:4]) + ')'
print('* [['+page.title()+"]] - '''NEW: " + enwiki_description+"'''")
if count > maxnum:
break
# print('Done! Edited ' + str(nummodified) + ' entries')
# EOF