/
PiRSS2Kindle.py
executable file
·61 lines (55 loc) · 2.01 KB
/
PiRSS2Kindle.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
59
60
61
import os
import sys
import sqlite3
import feedparser
import time
kindlemail = "insert@yourkindlemail.here"
today = time.strftime("%d-%m-%Y--%H-%M-%S")
print "creating file: " + today + ".html"
filename = today + ".html"
def create():
print "getting news..."
file = open(filename,'a')
file.write("<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"><title>Test</title></head><body>")
DBName = 'PiRSS2Kindle.sqlite'
con = sqlite3.connect(DBName)
with con:
cur = con.cursor()
cur.execute("SELECT * FROM KindleRSS")
RSSlist = []
title = ""
while True:
row = cur.fetchone()
if row == None:
break
entry = row[1]
d = feedparser.parse(entry)
title = d['feed']['title']
unread = len(d['entries'])
file.write("<a href=\"#" + title + "\">" + title + "</a> (" + str(unread) + ")<br />")
file.write("<mbp:pagebreak />")
cur = con.cursor()
cur.execute("SELECT * FROM KindleRSS")
while True:
row = cur.fetchone()
if row == None:
break
entry = row[1]
RSSlist.append(entry)
d = feedparser.parse(entry)
title = d['feed']['title']
print title
print row[0], row[1]
file.write("<div id=\"" + title + "\">" + title + "<mbp:pagebreak />")
for post in d.entries:
file.write("<b>" + post.title.encode("utf-8") + "</b><br />" + post.summary.encode("utf-8") + "<br /><br />")
file.write("</div><mbp:pagebreak />")
print "writing news to file..."
file.write("created by (<a href=\"https://github.com/xaos3k/PiRSS2Kindle\">PiRSS2Kindle</a>)</body></html>")
file.close()
create()
try:
print "sending file..."
os.system("echo \"\" | mail -s \"convert\" -A " + filename + " " + kindlemail)
except:
print "nope"