Skip to content

Instantly share code, notes, and snippets.

@cbare
Created June 3, 2014 00:57
Show Gist options
  • Select an option

  • Save cbare/1093d566354bebc04daa to your computer and use it in GitHub Desktop.

Select an option

Save cbare/1093d566354bebc04daa to your computer and use it in GitHub Desktop.
Retrieve the last 100 revisions of a wikipedia article
import synapseclient
from synapseclient import File, Project, Folder
syn = synapseclient.login()
## get latest 100 revisions of a wikipedia article
url = "http://en.wikipedia.org/w/api.php?action=query&titles=Crimea&prop=revisions&rvprop=ids|timestamp|flags|content&rvlimit=100&format=json"
response = requests.get(url)
crimea = response.json()
## make sure we got 100
print len(crimea['query']['pages']['163045']['revisions'])
## write to a file
with open('crimea.revisions.json', 'w') as f:
json.dump(crimea, f)
project = syn.get('syn2489903')
## store in Synapse
syn.store(File('crimea.revisions.json', parent=project))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment