Skip to content

Instantly share code, notes, and snippets.

@IanHopkinson
Created June 6, 2014 08:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanHopkinson/635e9fa156ec39285a05 to your computer and use it in GitHub Desktop.
Save IanHopkinson/635e9fa156ec39285a05 to your computer and use it in GitHub Desktop.
Get people appearing with a list of people from NewsReader
#!/usr/bin/env python
# encoding: utf-8
from __future__ import unicode_literals
import json
import requests
import scraperwiki
from collections import OrderedDict
def save_rows(row):
scraperwiki.sqlite.save(
unique_keys=['actor', 'actor2'],
data=row,
table_name="actors")
SUMMARY_TEMPLATE = OrderedDict({u'actor': None,
u'actor2': None,
u'numEvent': None,
u'comment': None})
names = ["David_Beckham", "Sepp_Blatter"]
query_string_template = "https://newsreader.scraperwiki.com/people_sharing_event_with_a_person/page/{page}?uris.0=dbpedia%3A{name}&output=json"
for name in names:
for page in range(1,22):
r = requests.get(query_string_template.format(name=name, page=page))
try:
actor_data = r.json()
except:
continue
for entry in actor_data["payload"]:
print name, page, entry["actor2"]
save_rows(entry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment