Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Created June 7, 2021 13:12
Show Gist options
  • Save blackknight36/f4b8b3e435370a45eddc3a513a1c7c4c to your computer and use it in GitHub Desktop.
Save blackknight36/f4b8b3e435370a45eddc3a513a1c7c4c to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import cgitb; cgitb.enable();
import requests
import string, sys, time, urllib
import xml.etree.ElementTree as et
def print_header():
print("""<html>
<head>
<title>%s</title>
<META http-equiv='Content-Type' content='text/html; charset=utf-8'>
<link rel='shortcut icon' type='image/x-icon' href='/iframe_test/favicon.ico'>
<link type='text/css' rel='stylesheet' href='/iframe_test/style.css'>
</head>
<body>""" %title)
def print_content_type():
print("Content-type: text/html\n\n")
def read_feed(url):
r = requests.get(url)
root = et.fromstring(r.text.replace('http', 'https'))
date = time.strftime("%B %d, %Y", time.localtime())
subtitle = root.find('lectionarytitle').text
fasting = root.find('fasting').text
icon = root.find('icon').text
#icon = icon.replace('http', 'https')
print("<table width='100%' border=2>")
print("<tr>")
print("<td colspan=2>")
print("{date} - {subtitle} - {fasting}".format(date=date, subtitle=subtitle, fasting=fasting))
print("</td>")
print("</tr>")
print("<tr>")
print("<td width='25%'><img src={icon} align='left' valign='middle'/></td>".format(icon=icon))
print("<td>")
print("Readings: ")
print("<ul class='readings'>")
for reading in root.findall('readings/reading'):
link = reading.find('publicurl').text
title = reading.find('translation/title').text
print("<li><a href='{link}' target='_new'>{title}</a></li>".format(link=link, title=title))
print('</ul>')
print("Saints: ")
print("<ul class='saints'>")
for saintfeast in root.findall('saintsfeasts/saintfeast'):
title = saintfeast.find('title').text
link = saintfeast.find('publicurl').text
print("<li><a href='{link}' target='_new'>{title}</a></li>".format(link=link, title=title))
print('</ul>')
print("</td>")
print("</tr>")
print("</table>")
title = "Goarch RSS reader"
print_content_type()
print_header()
read_feed('http://onlinechapel.goarch.org/daily.asp')
print("</body>\n</html>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment