Skip to content

Instantly share code, notes, and snippets.

@luchiago
Created October 8, 2020 13:03
Show Gist options
  • Save luchiago/7025f68e092ba000a7bfd5a95d6caeb4 to your computer and use it in GitHub Desktop.
Save luchiago/7025f68e092ba000a7bfd5a95d6caeb4 to your computer and use it in GitHub Desktop.
Fetch json from an API and saves in a file
import json
import requests
def save_file(file_name, data):
with open(file_name, 'w') as file:
json_data = json.dumps(data)
file.write(json_data)
def fetch_json(url, headers={}):
response = requests.get(url, headers=headers)
return response.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment