import pywikibot
from pywikibot import pagegenerators as pg
from pywikibot.data import api
import codecs
import sys
import datetime
from datetime import datetime,date,time

#this is actually just a test to see if this PAWS can handle a huge sparql query

query='select ?item where {?item wdt:P31 wd:Q5}'

def wd_sparql_query(spq):
  wikidatasite=pywikibot.Site('wikidata','wikidata') 
  generator=pg.WikidataSPARQLPageGenerator(spq,site=wikidatasite)
  for wd in generator:
    try:
      log_premature(wd.title())
      wd.get(get_redirect=True)
      yield wd
    except:
      pass    

for person in wd_sparql_query(query):
    print(person.title())