aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-02-01 09:26:08 +0100
committercedricbonhomme <devnull@localhost>2010-02-01 09:26:08 +0100
commitb348c9dd2be2010a6979c7c312b2c934a8d4d634 (patch)
tree69ad0e57ff5613f63f65f550fb47df2b1a6e4cc7
parentRelease 0.2. Improvements and description of articles. (diff)
downloadnewspipe-b348c9dd2be2010a6979c7c312b2c934a8d4d634.tar.gz
newspipe-b348c9dd2be2010a6979c7c312b2c934a8d4d634.tar.bz2
newspipe-b348c9dd2be2010a6979c7c312b2c934a8d4d634.zip
Added comments. Some improvements.
-rw-r--r--feedgetter.py32
-rw-r--r--pyAggr3g470r.py20
2 files changed, 34 insertions, 18 deletions
diff --git a/feedgetter.py b/feedgetter.py
index 276b6116..3d23b7a5 100644
--- a/feedgetter.py
+++ b/feedgetter.py
@@ -30,11 +30,22 @@ class FeedGetter(object):
"""
"""
def __init__(self):
+ """
+ Initializes the base and variables.
+ """
+ # Create the base if not exists.
+ 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
+ (article_id text PRIMARY KEY, article_date text, \
+ article_title text, article_link text, article_description text, \
+ feed_title text, feed_site_link text)''')
+ self.conn.commit()
+ self.c.close()
+
# mutex to protect the SQLite base
self.locker = threading.Lock()
- self.retrieve_feed()
-
def retrieve_feed(self):
"""
Parse the file 'feeds.lst' and launch a thread for each RSS feed.
@@ -64,21 +75,19 @@ class FeedGetter(object):
Executed in a thread.
SQLite objects created in a thread can only be used in that same thread !
"""
+ # Protect this part of code.
self.locker.acquire()
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
- (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
+ # Add the articles in the base.
self.add_into_sqlite(feedparser.parse(the_good_url))
self.conn.commit()
self.c.close()
+ # Release this part of code.
self.locker.release()
def add_into_sqlite(self, a_feed):
@@ -87,9 +96,9 @@ class FeedGetter(object):
"""
for article in a_feed['entries']:
try:
- content = article.description.encode('utf-8')
+ description = article.description.encode('utf-8')
except Exception, e:
- content = "No description"
+ description = "No description available."
sha256_hash = hashlib.sha256()
sha256_hash.update(article.link.encode('utf-8'))
@@ -101,7 +110,7 @@ class FeedGetter(object):
datetime(*article.updated_parsed[:6]), \
article.title.encode('utf-8'), \
article.link.encode('utf-8'), \
- content, \
+ description, \
a_feed.feed.title.encode('utf-8'), \
a_feed.feed.link.encode('utf-8')))
except sqlite3.IntegrityError:
@@ -116,4 +125,5 @@ if __name__ == "__main__":
print "./feed.lst not found"
exit(0)
- FeedGetter() \ No newline at end of file
+ feed_getter = FeedGetter()
+ feed_getter.retrieve_feed() \ No newline at end of file
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py
index 84e4382b..67cdd3d4 100644
--- a/pyAggr3g470r.py
+++ b/pyAggr3g470r.py
@@ -39,7 +39,9 @@ href="http://bitbucket.org/cedricbonhomme/pyaggr3g470r/">pyAggr3g470r (source co
class Root:
def index(self):
- self.dic = {}
+ """
+ Main page containing the list of feeds and articles.
+ """
html = htmlheader
html += htmlnav
html += """<br/><div class="right inner">"""
@@ -49,8 +51,7 @@ class Root:
html += """<a href="f/">Management of feed</a>"""
html += """</div> <div class="left inner">"""
-
- self.dic = self.retrieve_feed()
+ self.dic = self.load_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>"
@@ -72,7 +73,7 @@ class Root:
def description(self, article_id):
"""
- Display the description of an article.
+ Display the description of an article in a new Web page.
"""
html = htmlheader
html += htmlnav
@@ -85,7 +86,10 @@ class Root:
html += htmlfooter
return html
- def retrieve_feed(self):
+ def load_feed(self):
+ """
+ Load feeds in a dictionary.
+ """
list_of_articles = None
try:
conn = sqlite3.connect("./var/feed.db", isolation_level = None)
@@ -95,8 +99,10 @@ class Root:
except:
pass
+ # The key of dic is the title of the feed:
+ # dic[feed_title] = (article_id, article_date, article_title, article_link, article_description, feed_link)
+ dic = {}
if list_of_articles is not None:
- dic = {}
for article in list_of_articles:
if article[5] not in dic:
dic[article[5]] = [(article[0], article[1], article[2], article[3], article[4], article[6])]
@@ -108,7 +114,7 @@ class Root:
dic[feeds].sort(lambda x,y: compare(y[1], x[1]))
return dic
- return {}
+ return dic
index.exposed = True
f.exposed = True
bgstack15