This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitcoinupdate.py
58 lines (47 loc) · 1.49 KB
/
bitcoinupdate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf8 -*-
# This short script parses the RSS feed from bitcoinupdate.com and returns a nicely formatted
# block of HTML for the most recent entry.
#
# Author: Harald Schilly <hsy@bitcoin-austria.at>
# License: Apache 2.0
import requests as req
from dateutil.parser import parse as date_parser
from xml.dom.minidom import parseString as parse_xml
output = r"""
/*
Title: %(title)s
Description: Bitcoin Update Podcast
Date: %(date_f)s
Author: Bitcoin Update Podcast
Author_URL: http://bitcoinupdate.com
Thumbnail: /assets/pictures/thumbs/thumb-bitcoinupdate.png
*/
%(title)s
===
%(description)s
[Link zur aktuellen Folge](%(href)s)
"""
rss_url = "http://bitcoinupdate.com/podcast.php"
rss_data = req.get(rss_url)
if rss_data.status_code != 200:
raise Exception("status code not 200: %s" % rss_data.status_code)
rss = parse_xml(rss_data.text.encode("utf8"))
def get_val(el, what):
n = el.getElementsByTagName(what)[0]
return n.childNodes[0].data
most_recent_date = None
title, description, href = None, None, None
items = rss.getElementsByTagName("item")
for item in items:
pubDate = get_val(item, "pubDate")
t = get_val(item, "title")
d = get_val(item, "description")
h = get_val(item, "link")
date = date_parser(pubDate)
if most_recent_date is None or date > most_recent_date:
title, description, href = t, d, h
most_recent_date = date
date_f = date.strftime("%Y/%m/%d")
out = (output % locals()).encode('utf-8')
print(out)