Created
October 8, 2013 12:47
-
-
Save pekkavaa/6884151 to your computer and use it in GitHub Desktop.
Lukee RSS-syötteen suomeksi.
This file contains hidden or 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
import feedparser | |
import argparse | |
import subprocess | |
from time import mktime | |
from datetime import datetime | |
def get_last_edited(): | |
f = open('last_modified.temp', 'r') | |
data = f.read() | |
f.close() | |
return data | |
def set_last_edited(dtime): | |
f = open('last_modified.temp', 'w') | |
f.write(str(dtime)) | |
f.close() | |
def speak(msg, args=None): | |
# default speed is 160 wpm | |
l = ['espeak', '-k10', '-v', 'fi', '-s', '140', '"'+msg+'"'] | |
subprocess.call(l) | |
def check_if_news(d): | |
last_modified = d.feed.modified_parsed | |
last_datetime = float(mktime(last_modified)) | |
print "modified: " + str(last_datetime) | |
print "last modified: " + get_last_edited() | |
if float(last_datetime) == float(get_last_edited()): | |
return False | |
set_last_edited(last_datetime) | |
return True | |
parser = argparse.ArgumentParser(description="Reads the top news aloud") | |
parser.add_argument('rss_location', help="Location of the RSS feed to read.") | |
parser.add_argument('--all', action='store_true', help="Read all news from the feed aloud.") | |
parser.add_argument('--skip_check', action='store_true', help="Do not check feed timestamp.") | |
args = parser.parse_args() | |
d = feedparser.parse(args.rss_location) | |
print (d.feed.title) | |
if (not check_if_news(d) and not (args.skip_check)): | |
print "no news" | |
exit(0) | |
#print "ID: " + str(d.feed.modified_parsed) | |
if args.all: | |
for entry in d.entries: | |
print repr(entry.title) | |
speak(entry.title) | |
else: | |
# read the top entry | |
entry = d.entries[0] | |
print entry.title | |
speak(entry.title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment