Last active
August 29, 2015 14:03
-
-
Save urkonn/35e0a95dd52dbf068e32 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import urllib2 | |
import urllib | |
import json | |
import pprint | |
request = urllib2.Request( | |
'http://192.168.33.20:8080/api/action/package_show') | |
request.add_header('Authorization', 'XXXXX') | |
id_list = ['xxxx', 'yyyy', 'zzzz'] | |
for item in id_list: | |
id_dict = {'id': item} | |
id_string = urllib.quote(json.dumps(id_dict)) | |
response = urllib2.urlopen(request, id_string) | |
assert response.code == 200 | |
response_dict = json.loads(response.read()) | |
assert response_dict['success'] is True | |
show_package = response_dict['result'] | |
pprint.pprint(show_package) | |
def replace_license(license_key, new_value): | |
for key in show_package.keys(): | |
if key == license_key: | |
show_package[key] = new_value | |
replace_license('license_id', '') | |
replace_license('license_title', '') | |
replace_license('license_url', '') | |
pprint.pprint(show_package) | |
data_string = urllib.quote(json.dumps(show_package)) | |
request1 = urllib2.Request( | |
'http://192.168.33.20:8080/api/action/package_update') | |
request1.add_header('Authorization', 'XXXX') | |
response1 = urllib2.urlopen(request1, data_string) | |
assert response1.code == 200 | |
response_dict1 = json.loads(response1.read()) | |
assert response_dict1['success'] is True | |
updated_package = response_dict1['result'] | |
pprint.pprint(updated_package) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment