Skip to content

Instantly share code, notes, and snippets.

@Abbe98
Last active July 9, 2016 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abbe98/5e1ec02a8913f7dc100eae3b8635dab6 to your computer and use it in GitHub Desktop.
Save Abbe98/5e1ec02a8913f7dc100eae3b8635dab6 to your computer and use it in GitHub Desktop.
import sys, pywikibot
from pywikibot import pagegenerators
pywikibot.handle_args(sys.argv[1:])
site = pywikibot.Site('wikidata', 'wikidata')
repo = site.data_repository()
query = 'SELECT ?item ?population WHERE{ ?item wdt:P31 wd:Q515 . ?item wdt:P1082 ?population . FILTER (?population > 100000) MINUS { ?item wdt:P31 wd:Q1549591 }} ORDER BY DESC(?population)'
generator = pagegenerators.WikidataSPARQLPageGenerator(query, site=site)
for item in generator:
claim = pywikibot.Claim(repo, 'P31')
target = pywikibot.ItemPage(repo, 'Q1549591')
claim.setTarget(target)
item.addClaim(claim)
@Abbe98
Copy link
Author

Abbe98 commented Jul 9, 2016

This bot can't be simulated see:
https://phabricator.wikimedia.org/T76694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment