<jupyter_start><jupyter_text>Code for part 1: Data retrieval system<jupyter_code>import json
import requests
def get_top_stories(top=10):
    sess = requests.Session()
    url = 'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'
    html = sess.get(url)
    ids = json.loads(html.content.decode('utf-8'))
    ids = ids[:top]
    return ids
ids = get_top_stories(top=10)
ids
def get_item_dict(ids):
    item_dict = {}
    sess = requests.Session()
    for item in ids:
        url = 'https://hacker-news.firebaseio.com/v0/item/{}.json?print=pretty'.format(item)
        html = sess.get(url)
        item_data = json.loads(html.content.decode('utf-8'))
        item_dict[item] = item_data
    return item_dict
item_dict = get_item_dict(ids)
item_dict
def process_info(item_dict):
    titles = []
    for key in item_dict.keys():
        titles.append(item_dict[key].get('title'))
    item_info = "... ".join([x for x in titles])
    return item_info
process_info(item_dict)
def get_headlines():
    top_stories_ids = get_top_stories()
    item_dict = get_item_dict(top_stories_ids)
    data = process_info(item_dict)
    return data
get_headlines()<jupyter_output><empty_output>