Skip to content

Instantly share code, notes, and snippets.

@VorontsovIE
Created January 18, 2017 08:23
Show Gist options
  • Save VorontsovIE/abb28a5381fc1beca463aa4316acaf47 to your computer and use it in GitHub Desktop.
Save VorontsovIE/abb28a5381fc1beca463aa4316acaf47 to your computer and use it in GitHub Desktop.
import os, sys
currentdir = os.path.dirname(os.path.abspath(__file__))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
import wikilib
import parsing_dates
import apiRequest
import parseToDB
import sys
#name = 'Battle_of_Kulikovo'
#name = 'Battle_of_Stalingrad'
infoboxType = sys.argv[1]
for line in sys.stdin:
try:
name = line.strip()
page = apiRequest.getPage(name)
infoboxData = parseToDB.infobox_parser(infoboxType)(wikilib.get_infobox(page))
if 'date' not in infoboxData:
print('Missing `date` field in infobox for article', name, file = fw)
continue
our_parse_date = infoboxData['date']
date_from_wikidata = apiRequest.getWikidataDate(apiRequest.getWikidataProperties(apiRequest.getWikidataID(name)))
message = ''
if our_parse_date == ([None, None, None], [None, None, None]):
message = 'Error - We can not parse this date'
elif (date_from_wikidata is None) or (date_from_wikidata == ([None, None, None], [None, None, None])):
message = 'Error - Wikidata has not this date. We can add our date'
elif our_parse_date == date_from_wikidata:
message = 'Ok'
elif our_parse_date != date_from_wikidata:
message = 'Error - Our date does not coincide with date from Wikidata'
fw = sys.stdout
#print('infobox ->', infoboxData, file = fw)
print('Name:', name, file = fw)
print('Infobox:', file = fw)
for (key, value) in infoboxData.items():
print(key, value, file = fw)
print('Our date:', our_parse_date, file = fw)
print('Date from Wikidata:', date_from_wikidata, file = fw)
print('Result:', message, file = fw)
print('-------------------------------------', file = fw)
except Exception as e:
print('Exception:', e, file = fw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment