Created
January 20, 2019 20:27
-
-
Save wrparker/efd770256cfd10fda46715b0f25ea543 to your computer and use it in GitHub Desktop.
indeed-atsdi.com python API consumption
This file contains hidden or 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 | |
| import ntpath | |
| url = 'https://indeed-atsdi.com/api/get_upload_url' | |
| file_names = ['current_version5.txt', 'file2.tsv'] | |
| API_KEY = 'XXXXXXXXX' | |
| headers = {'Accept': 'application/json', | |
| 'Content-Type': 'application/json', | |
| 'token': API_KEY} | |
| # This gets the presigned URLs | |
| r = requests.post(url, | |
| headers=headers, | |
| json=json.dumps({'file_names': file_names})) | |
| try: | |
| r.raise_for_status() | |
| urls = r.json() | |
| # Upload file(s) to AWS. | |
| for file_name in file_names: | |
| with open(file_name, 'rb') as data: | |
| upload_result = requests.put(urls[ntpath.basename(file_name)], data=data) | |
| upload_result.raise_for_status() | |
| except: | |
| print (r.json()) | |
| print("Error occured.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment