I have a cURL script that, when run via the CMD Prompt window, returns the requested data. However I am trying to figure out how to automate this process via Python (either 2.7 - 3.6) so that it returns a csv file instead. (I am using the latest version of Python allowed when working with either ArcGIS ArcMap and/or ArcGIS Pro mapping software.)
I have basic Python skills and need help getting the script right. Below is the cURL script I push via the CMD Prompt window. How do I do this with Python so that it returns a csv file?
I have looked up various examples which seem somewhat different in the parameters required. I have tried to modify a few, but couldn't get them to work. I am not set on one method verses another, so I am open to different solutions, just need to find one that works. My cURL doesn't require a username, just an API key and some basic search parameters. Most examples I found required both a user name and password.
Current cURL code...
curl -H "Authorization: Basic myAPIkey" “https://website.com/api/incident?search_from=2019-08-01&search_to=2019-08-31”
I want to be able to download a csv file. The errors I have been getting vary depending upon which example and method I was trying to replicate.
Thanks for any assistance in advance.
UPDATE
I managed to figure out the Python request option to submit my initial request:
import requests,json
headers = {'Authorization': 'Basic APIKEY'}
response = requests.get("https://website.com/api/incident?search_from=2019-08-01&search_to=2019-08-31&country_id=5", headers=headers)
print json.dumps(response.json(), indent=4)
It now returns I believe a json file, however I am having issues still on parsing it properly to either save as a csv or as a new Feature Class in ArcGIS.
The print statement returns the following:
{ "message": "", "total": 1, "data": { "total": 353, "results": [ { "mgrs": "33S UR 71235 88779", "weight": 0, "type_id": "1", "longitude": "13.63040400", "date": "2019-08-31", "latitude": "32.42868600", "icon": "assets/images/map_icons/Announcement.png", "id": "507188", "quantity": "1" }, { "mgrs": "33S US 40233 29235", "weight": 1, "type_id": "3", "longitude": "13.29387300", "date": "2019-08-31", "latitude": "32.78945800", "icon": "assets/images/map_icons/ArmedClashes.png", "id": "507187", "quantity": "1" } ] } }
I want to be able to read and right the "results" list into a csv format with a proper header column.
Any advice would be greatly appreciated.
Thanks in advance.