refactoring, improvement of debug-output

This commit is contained in:
Ronald Schaten 2010-10-29 00:28:25 +02:00
parent f979f32bae
commit daa2d204c1

View File

@ -124,7 +124,17 @@ session = Session()
#session.add(Feed('http://www.heise.de/newsticker/heise-atom.xml', 1, 0, 0, 1))
#session.add(Feed('http://blog.schatenseite.de/feed/', 1, 0, 0, 1))
for feed in session.query(Feed).filter_by(enabled=1).order_by(Feed.id):
def process_feed_entry(feed, entry):
query = session.query(Entry).filter_by(feed_id=feed.id, title=entry.title.encode('latin-1', 'replace'))
try:
thisentry = query.one()
thisentry.update(entry)
return "-"
except Exception, e:
feed.entry.append(Entry(entry))
return "+"
def fetch_single_feed(feed):
print "fetching %s" % feed.url
parser = feedparser.parse(feed.url)
print "processing feed info..."
@ -136,16 +146,24 @@ for feed in session.query(Feed).filter_by(enabled=1).order_by(Feed.id):
feed.feedinfo = Feedinfo(parser)
print "processing feed entries: ",
entries_new = 0
entries_total = 0
for entry in parser.entries:
query = session.query(Entry).filter_by(feed_id=feed.id, title=entry.title.encode('latin-1', 'replace'))
try:
thisentry = query.one()
sys.stdout.write("-")
thisentry.update(entry)
except Exception, e:
sys.stdout.write("+")
feed.entry.append(Entry(entry))
entries_total = entries_total + 1
ret = process_feed_entry(feed, entry)
if ret == "+":
entries_new = entries_new + 1
sys.stdout.write(ret)
print " (%d/%d new)" % (entries_new, entries_total)
def fetch_all_feeds():
print "fetching all feeds..."
for feed in session.query(Feed).filter_by(enabled=1).order_by(Feed.id):
fetch_single_feed(feed)
print
if __name__ == "__main__":
print "main"
fetch_all_feeds()
session.commit()