Curso_Intensivo_de_PYTHON/chapter_17/hn_article.py
2023-06-02 17:22:53 +02:00

13 lines
385 B
Python

import requests
import json
# Make an API call, and store the response.
url = 'https://hacker-news.firebaseio.com/v0/item/19155826.json'
r = requests.get(url)
print(f"Status code: {r.status_code}")
# Explore the structure of the data.
response_dict = r.json()
readable_file = 'data/readable_hn_data.json'
with open(readable_file, 'w') as f:
json.dump(response_dict, f, indent=4)