Created
August 20, 2018 18:09
-
-
Save nishadhka/b1d5bd4ecd1c73ea52be4ab2521f62d4 to your computer and use it in GitHub Desktop.
Ushahidi form to key mapper, using attributes API
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 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