import time
import pywikibot as bot
from pywikibot import pagegenerators as pg
site = bot.Site('wikidata', 'wikidata')

with open('born.rq', 'r') as query_file:
    QUERY = query_file.read().replace('\n', '')
    print(QUERY)

generator = pg.WikidataSPARQLPageGenerator(QUERY, site=site)

start_time = time.time()
maxSitelinks = 0
for item in generator:
    item_dict = item.get()
    numberSitelinks = len(list(item_dict["sitelinks"].keys()))
    if numberSitelinks > maxSitelinks:
        maxSitelinks = numberSitelinks
        maxSitelinksItem = item

print("--- %s seconds ---" % (time.time() - start_time))
print(maxSitelinksItem)
SELECT ?item (YEAR(?date) as ?year) WHERE{    BIND(MONTH(NOW()) AS ?nowMonth)    BIND(DAY(NOW()) AS ?nowDay)    ?item wdt:P569 ?date .    ?item wdt:P21 wd:Q6581072 .    FILTER (MONTH(?date) = ?nowMonth && DAY(?date) = ?nowDay && YEAR(?date) > 1800)}LIMIT 1000
--- 67.94803977012634 seconds ---
[[wikidata:Q202381]]