Created
October 13, 2018 03:09
-
-
Save jspraul/3e7e6b080ac230f664cc0b737fea6774 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3 | |
# HN top 10 in 45 seconds or less using 'say' on Mac | |
import datetime | |
import os | |
import requests | |
import subprocess | |
import time | |
import xml.etree.ElementTree | |
def get(): | |
cache = './hn-daily.rss' | |
if not os.path.exists(cache) or time.time() - os.path.getmtime(cache) > 3600: | |
print('Downloading RSS...\n') | |
r = requests.get('http://www.daemonology.net/hn-daily/index.rss') | |
with open(cache, "w+") as newFile: | |
newFile.write(r.text) | |
with open(cache) as read: | |
return read.read() | |
root = xml.etree.ElementTree.fromstring( get() ) | |
output = root[0].find('item').find('title').text.replace('-',' ') +'[[slnc 1000]]\n' | |
root = xml.etree.ElementTree.fromstring( '<z>'+ root[0].find('item').find('description').text.replace('<br>','<br />') +'</z>' ) | |
x = 1 | |
for child_li in root[1]: | |
output = output + 'Story Number {0}: {1}[[slnc 1000]]\n'.format(x, child_li.find('span').find('a').text) | |
x = x + 1 | |
print(output.replace('[[slnc 1000]]','').replace('Story Number ','')) | |
subprocess.run(['say', '-v', 'Samantha', '-r', '300'], input=output.encode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment