Skip to content

Instantly share code, notes, and snippets.

@pudo
Created May 31, 2012 13:40
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 pudo/2843491 to your computer and use it in GitHub Desktop.
Save pudo/2843491 to your computer and use it in GitHub Desktop.
A python sample of how to script OS loads.
import requests
import sys
OPENSPENGING_DATASET = 'http://openspending.org/br-cgu/'
OPENSPENDING_AUTH = ('user', 'password')
if __name__ == '__main__':
# 1) Make a source within OS, linking to the URL of the source CSV
source_url = sys.argv[1]
requests.post(OPENSPENGING_DATASET + 'sources', auth=OPENSPENDING_AUTH,
data={'url': source_url})
# 2) Find out the ID for the new source object
# This should be in the response to 1) but isn't; will fix.
res = requests.get(OPENSPENGING_DATASET + 'sources.json',
auth=OPENSPENDING_AUTH)
ids = map(lambda s: s.get('id'), res.json)
latest_id = max(ids)
# 3) Initiate a load of that source
# Will queue the operation and return immediately.
requests.post(OPENSPENGING_DATASET + 'sources/' + str(latest_id),
auth=OPENSPENDING_AUTH,
data={'url': source_url})
@nickstenning
Copy link

OPENSPENGING ftw.

@pudo
Copy link
Author

pudo commented May 31, 2012

SPENGING, N: ze lesser-used, German spelling of spending. Ve zink its more natural.

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