Created
May 31, 2012 13:40
-
-
Save pudo/2843491 to your computer and use it in GitHub Desktop.
A python sample of how to script OS loads.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
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
OPENSPENGING ftw.