Skip to content

Instantly share code, notes, and snippets.

@flyingduck92
Created October 7, 2018 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyingduck92/a44ff1ae984b00a3fb3c0e2a37d581e9 to your computer and use it in GitHub Desktop.
Save flyingduck92/a44ff1ae984b00a3fb3c0e2a37d581e9 to your computer and use it in GitHub Desktop.
This is a test gist
from xml.etree import ElementTree
from collections import namedtuple
import requests
Episode = namedtuple('Episode', 'title link pubdate show_id')
episode_data = {}
def download_info():
"""
Will download from rss talkpython
:return: True if exists, False if doesn't exists
"""
url = 'https://talkpython.fm/episodes/rss'
# TODO: request data from url and show status
res = requests.get(url)
res.raise_for_status()
# TODO: put response to html dom using ElementTree
dom = ElementTree.fromstring(res.text)
# TODO: find all items and count episode
items = dom.findall('channel/item')
episode_count = len(items)
# TODO: loop item and put episode to dictionary
for idx, item in enumerate(items):
episode = Episode(
item.find('title').text,
item.find('link').text,
item.find('pubDate').text,
episode_count - idx - 1
)
episode_data[episode.show_id] = episode
# TODO: refers get_episode method to Episode tuple
def get_episode(show_id: int) -> Episode:
return episode_data.get(show_id)
def get_latest_show_id():
return max(episode_data.keys())
@flyingduck92
Copy link
Author

Yeah, this is gist pretty good for testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment