commit bea5daebe99ff92fffec41f86332fc3b3621162e
parent 748d7c673ea8efc9164e2386f32f93847b617d8b
Author: Christoph Lohmann <20h@r-36.net>
Date: Mon, 28 Apr 2014 20:50:41 +0200
Adding some commands and uuid handling.
uuid: Better difference handling in feed merge.
commands: Handle ids and reset.
Diffstat:
feed.py | | | 12 | ++++++++++-- |
feeddb.py | | | 21 | +++++++++++++++++---- |
zs.py | | | 39 | +++++++++++++++++++++++++++++++++++---- |
3 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/feed.py b/feed.py
@@ -183,8 +183,16 @@ def parse(astr):
else:
article["id"] = article["text"][:30]
+ article["uuid"] = "%s" % (article["updated"])
+ for e in ("id", "title", "file"):
+ if e in article:
+ article["uuid"] = "%s-%s" % \
+ (article["uuid"],\
+ article[e])
+
# sanity checks
- if "title" not in article and "text" not in article:
+ if "title" not in article and "text" not in article \
+ and "file" not in article:
continue
articles.append(article)
@@ -197,5 +205,5 @@ class feedopener(urllib.request.FancyURLopener):
urllib.request._urlopener = feedopener
def fetch(uri):
- return parse(urllib.request.urlopen(uri).read())
+ return parse(urllib.request.urlopen(uri, timeout=5).read())
diff --git a/feeddb.py b/feeddb.py
@@ -164,8 +164,8 @@ class feeddb(object):
history = feed["articles"]
for article in curfeed["articles"]:
- a = [art for art in history if art["id"] == \
- article["id"]]
+ a = [art for art in history if art["uuid"] == \
+ article["uuid"]]
if len(a) == 0:
article["unread"] = True
history.append(article)
@@ -201,14 +201,27 @@ class feeddb(object):
return rfeed
+ def setarticleunread(self, uri, ids):
+ feed = self.readfeed(uri)
+ if feed == None:
+ return
+
+ for article in feed["articles"]:
+ a = [art for art in feed["articles"] if art["uuid"] == \
+ ids]
+ if len(a) > 0:
+ for aa in a:
+ aa["unread"] = True
+ self.writefeed(uri, feed);
+
def setreadarticles(self, uri, curfeed=None):
feed = self.readfeed(uri)
if feed == None:
return
for article in curfeed["articles"]:
- a = [art for art in curfeed["articles"] if art["id"] == \
- article["id"]]
+ a = [art for art in curfeed["articles"] if art["uuid"] == \
+ article["uuid"]]
if len(a) > 0:
for aa in a:
aa["unread"] = False
diff --git a/zs.py b/zs.py
@@ -15,6 +15,11 @@ import urllib.error
import socket
import http.client
+def sendfeed(db, ufeed):
+ feedemail.send(ufeed, db.cfg["email"], db.cfg["smtphost"], \
+ db.cfg["smtpport"], db.cfg["smtpssl"], \
+ db.cfg["smtpuser"], db.cfg["smtppassword"])
+
def run(db, selfeed=None, dryrun=False):
feeduris = db.listfeeds()
@@ -29,6 +34,7 @@ def run(db, selfeed=None, dryrun=False):
retries = db.getretry(feeduri)
estr = None
print("fetch %s" % (feeduri))
+ curfeed = None
try:
curfeed = feed.fetch(feeduri)
except urllib.error.HTTPError as err:
@@ -37,6 +43,8 @@ def run(db, selfeed=None, dryrun=False):
retries += 1
except socket.gaierror:
continue
+ except socket.timeout:
+ continue
except urllib.error.URLError:
continue
except TimeoutError:
@@ -76,11 +84,8 @@ def run(db, selfeed=None, dryrun=False):
if len(ufeed["articles"]) > 0:
print("cur %d unread %d" % (clen, \
len(ufeed["articles"])))
-
if dryrun == False:
- feedemail.send(ufeed, db.cfg["email"], db.cfg["smtphost"], \
- db.cfg["smtpport"], db.cfg["smtpssl"], \
- db.cfg["smtpuser"], db.cfg["smtppassword"])
+ sendfeed(db, ufeed)
db.setreadarticles(feeduri, ufeed)
def usage(app):
@@ -121,6 +126,12 @@ def main(args):
else:
db.cfg[args[2]] = args[3]
print("%s = '%s'" % (args[2], db.cfg[args[2]]))
+
+ elif args[1] == "cfgdel":
+ if len(args) < 3:
+ usage(args[0])
+ if args[2] in db.cfg:
+ del db.cfg[args[2]]
elif args[1] == "add":
if len(args) < 3:
@@ -131,6 +142,26 @@ def main(args):
for f in db.listfeeds():
print(f)
+ elif args[1] == "listuuids":
+ if len(args) < 3:
+ usage(args[0])
+ feed = db.readfeed(args[2])
+ for art in feed["articles"]:
+ print("%s: %s: %s" % (art["uuid"], art["link"],\
+ art["title"]))
+
+ elif args[1] == "unread":
+ if len(args) < 4:
+ usage(args[0])
+ db.setarticleunread(args[2], args[3])
+
+ elif args[1] == "resend":
+ if len(args) < 3:
+ usage(args[0])
+ ufeed = db.unreadarticles(args[2])
+ sendfeed(db, ufeed)
+ db.setreadarticles(args[2], ufeed)
+
elif args[1] == "del":
if len(args) < 3:
usage(args[0])