Skip to content

Instantly share code, notes, and snippets.

@nishadhka
Created August 20, 2018 18:09
Show Gist options
  • Save nishadhka/b1d5bd4ecd1c73ea52be4ab2521f62d4 to your computer and use it in GitHub Desktop.
Save nishadhka/b1d5bd4ecd1c73ea52be4ab2521f62d4 to your computer and use it in GitHub Desktop.
Ushahidi form to key mapper, using attributes API
import requests
import json
oauth_url = 'http://sample_ushahidinstance/platform/oauth/token'
oauth_d = {
"grant_type": "password",
"scope": "apikeys posts country_codes media forms api tags savedsearches sets users stats layers config messages notifications webhooks contacts roles permissions csv tos dataproviders",
"client_id": "ushahidiui",
"client_secret": "35e7f0bca957836d05ca0492211b0ac707671261",
"password": "passwrod", # replace with your password
"username": "email" # replace with your email login
}
oauth_creds = requests.post(oauth_url, json=oauth_d).text
print(oauth_creds)
post_url = 'http://sample_ushahidinstance/platform/api/v3/forms/attributes/'
out = requests.get(post_url, headers=headers)
data = json.loads(out.text)
#print(out.text)
with open('attributes.json', 'w') as outfile:
json.dump(data, outfile)
ukey=[]
ufield=[]
for dat in data['results']:
ukey.append(dat['key'])
ufield.append(dat['label'])
db=pd.DataFrame()
db['ukey']=ukey
db['ufield']=ufield
db.to_csv('form_to_key.py')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment