Technical development: Difference between revisions
Amy Suo Wu (talk | contribs) (Created page with "==pulling categories from mediawiki(SNPedia)== *Feb 15th (with Fako & Natasha). From the terminal (local host), this script pulls categories (default on 10) from SNPedia. <sou...") |
Amy Suo Wu (talk | contribs) No edit summary |
||
Line 2: | Line 2: | ||
*Feb 15th (with Fako & Natasha). From the terminal (local host), this script pulls categories (default on 10) from SNPedia. | *Feb 15th (with Fako & Natasha). From the terminal (local host), this script pulls categories (default on 10) from SNPedia. | ||
<source lang="python"> | |||
#!/usr/bin/python | #!/usr/bin/python | ||
Line 20: | Line 20: | ||
for page in f['query']['pages'].itervalues(): | for page in f['query']['pages'].itervalues(): | ||
print page['title'] | print page['title'] | ||
</source> | |||
Revision as of 22:28, 15 February 2011
pulling categories from mediawiki(SNPedia)
- Feb 15th (with Fako & Natasha). From the terminal (local host), this script pulls categories (default on 10) from SNPedia.
#!/usr/bin/python
import json, urllib2
search = u'Rs1001179' # quotes are string.
url = u'http://www.snpedia.com/api.php?action=query&format=json&redirects=true&generator=categories&titles=' + search
request = urllib2.Request(url)
response = urllib2.urlopen(request)
result = response.read()
f = json.loads(result)
print type(f)
g = json.dumps(f) # dump makes back into a string
print type(g)
for page in f['query']['pages'].itervalues():
print page['title']