aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--feedgetter.py21
-rw-r--r--pyAggr3g470r.py40
2 files changed, 42 insertions, 19 deletions
diff --git a/feedgetter.py b/feedgetter.py
index a99d8a29..624d8511 100644
--- a/feedgetter.py
+++ b/feedgetter.py
@@ -9,6 +9,7 @@ __license__ = "GPLv3"
import re
import sqlite3
+import hashlib
import threading
import feedparser
@@ -68,9 +69,9 @@ class FeedGetter(object):
self.conn = sqlite3.connect("./var/feed.db", isolation_level = None)
self.c = self.conn.cursor()
self.c.execute('''create table if not exists rss_feed
- (date text, feed_title text, feed_site_link text, \
- article_title text, article_link text PRIMARY KEY, \
- article_content text)''')
+ (article_id text PRIMARY KEY, article_date text, \
+ article_title text, article_link text, article_description text, \
+ feed_title text, feed_site_link text)''')
# add the articles in the base
self.add_into_sqlite(feedparser.parse(the_good_url))
@@ -89,14 +90,20 @@ class FeedGetter(object):
content = article.description.encode('utf-8')
except Exception, e:
content = "No description"
+
+ sha256_hash = hashlib.sha256()
+ sha256_hash.update(article.link.encode('utf-8'))
+ article_id = sha256_hash.hexdigest()
+
try:
- self.c.execute('insert into rss_feed values (?,?,?,?,?,?)', (\
+ self.c.execute('insert into rss_feed values (?,?,?,?,?,?,?)', (\
+ article_id, \
datetime(*article.updated_parsed[:6]), \
- a_feed.feed.title.encode('utf-8'), \
- a_feed.feed.link.encode('utf-8'), \
article.title.encode('utf-8'), \
article.link.encode('utf-8'), \
- content))
+ content, \
+ a_feed.feed.title.encode('utf-8'), \
+ a_feed.feed.link.encode('utf-8')))
except sqlite3.IntegrityError:
pass
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py
index d8d8210f..fdc80563 100644
--- a/pyAggr3g470r.py
+++ b/pyAggr3g470r.py
@@ -39,6 +39,7 @@ href="http://bitbucket.org/cedricbonhomme/pyaggr3g470r/">pyAggr3g470r (source co
class Root:
def index(self):
+ self.dic = {}
html = htmlheader
html += htmlnav
html += """<br/><div class="right inner">"""
@@ -49,15 +50,17 @@ class Root:
html += """</div> <div class="left inner">"""
- dic = self.retrieve_feed()
- for rss_feed in dic.keys():
- html += '<h2><a href="' + rss_feed.encode('utf-8') + \
- '">' + dic[rss_feed][0][1].encode('utf-8') + "</a></h2>"
+ self.dic = self.retrieve_feed()
+ for rss_feed in self.dic.keys():
+ html += '<h2><a href="' + self.dic[rss_feed][0][5].encode('utf-8') + \
+ '">' + rss_feed.encode('utf-8') + "</a></h2>"
- for article in dic[rss_feed]:
- html += article[0].encode('utf-8') + " - " + \
+ for article in self.dic[rss_feed]:
+ html += article[1].encode('utf-8') + " - " + \
'<a href="' + article[3].encode('utf-8') + \
- '">' + article[2].encode('utf-8') + "</a><br />"
+ '">' + article[2].encode('utf-8') + "</a>" + \
+ """ - [<a href="/description/%s">description</a>]""" % (article[0].encode('utf-8'),) + \
+ "<br />"
html += htmlfooter
return html
@@ -67,6 +70,19 @@ class Root:
"""
return "Hello world !"
+ def description(self, article_id):
+ """
+ Display the description of an article.
+ """
+ html = htmlheader
+ html += htmlnav
+ html += """</div> <div class="left inner">"""
+ for rss_feed in self.dic.keys():
+ for article in self.dic[rss_feed]:
+ if article_id == article[0]:
+ html += article[4].encode('utf-8')
+ html += htmlfooter
+ return html
def retrieve_feed(self):
list_of_articles = None
@@ -81,21 +97,21 @@ class Root:
if list_of_articles is not None:
dic = {}
for article in list_of_articles:
- if article[2] not in dic:
-
- dic[article[2]] = [(article[0], article[1], article[3], article[4])]
+ if article[5] not in dic:
+ dic[article[5]] = [(article[0], article[1], article[2], article[3], article[4], article[6])]
else:
- dic[article[2]].append((article[0], article[1], article[3], article[4]))
+ dic[article[5]].append((article[0], article[1], article[2], article[3], article[4], article[6]))
# sort articles by date for each feeds
for feeds in dic.keys():
- dic[feeds].sort(lambda x,y: compare(y[0], x[0]))
+ dic[feeds].sort(lambda x,y: compare(y[1], x[1]))
return dic
return {}
index.exposed = True
f.exposed = True
+ description.exposed = True
def compare(stringtime1, stringtime2):
bgstack15