Skip to content

Instantly share code, notes, and snippets.

@CristianCantoro
Forked from atomotic/1_README.md
Last active December 27, 2015 00: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 CristianCantoro/7236527 to your computer and use it in GitHub Desktop.
Save CristianCantoro/7236527 to your computer and use it in GitHub Desktop.

resolve SBN authority id to wikipedia.it

(requires jq and gnu parallel)

  • get all Q ids with P396 property > ids.txt

~ make get

~ make resolv

  • configure the apache virtualhost to use the rewrite map (now allowed in .htaccess)
RewriteEngine on
RewriteMap iccu txt:/{FULL_PATH}/resolv.map
RewriteRule ^/r/(.*)$ ${iccu:$1} [R]
RewriteEngine on
RewriteMap iccu txt:/{FULL_PATH}/resolv.map
RewriteRule ^/r/IT(\\|/)ICCU(\\|/)(.{4})(\\|/)(.*)$ ${iccu:ITICCU$3$5} [R]
#!/usr/bin/env python
import sys
import pywikibot
q = "Q{}".format(sys.argv[1])
site = pywikibot.Site('it','wikipedia')
repo = site.data_repository()
item = pywikibot.ItemPage(repo, q)
data = item.get()
iccu = item.claims['P396'][0].getTarget()
title = "http://it.wikipedia.org/wiki/{}".format(data['sitelinks']['itwiki'].replace (" ", "_"))
print iccu.replace('\\',''), title
get:
curl -s "http://208.80.153.172/api?q=claim\[396\]" | jq ".items[]" > ids.txt
resolve:
parallel -j4 ./make-resolver-map.py {} :::: ids.txt > resolv.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment