aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-02-28 12:44:40 +0100
committercedricbonhomme <devnull@localhost>2010-02-28 12:44:40 +0100
commit286d33a3362d46de7f8a5419ad2dd8a5ea1c51d5 (patch)
tree7848910b31b08042d92eb7cf03e10b93465d4c68 /utils.py
parentMinor enhancement. (diff)
downloadnewspipe-286d33a3362d46de7f8a5419ad2dd8a5ea1c51d5.tar.gz
newspipe-286d33a3362d46de7f8a5419ad2dd8a5ea1c51d5.tar.bz2
newspipe-286d33a3362d46de7f8a5419ad2dd8a5ea1c51d5.zip
Minor enhancements of the code.
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/utils.py b/utils.py
index e2294446..b7434636 100644
--- a/utils.py
+++ b/utils.py
@@ -31,11 +31,11 @@ def top_words(dic_articles, n=10):
words = {}
articles_content = ""
for rss_feed_id in dic_articles.keys():
- for article in dic_articles[rss_feed_id]:
- articles_content += remove_html_tags(article[4].encode('utf-8'))
+ for article in dic_articles[rss_feed_id]:
+ articles_content += remove_html_tags(article[4].encode('utf-8'))
words_gen = (word.strip(punctuation).lower() \
- for word in articles_content.split() \
- if len(word) >= 5)
+ for word in articles_content.split() \
+ if len(word) >= 5)
words = defaultdict(int)
for word in words_gen:
words[word] += 1
@@ -103,13 +103,11 @@ def compare(stringtime1, stringtime2):
return -1
elif datetime1 > datetime2:
return 1
- else:
- return 0
-
+ return 0
def load_feed():
"""
- Load feeds in a dictionary.
+ Load feeds and articles in a dictionary.
"""
list_of_feeds = None
list_of_articles = None
@@ -117,11 +115,9 @@ def load_feed():
conn = sqlite3.connect("./var/feed.db", isolation_level = None)
c = conn.cursor()
list_of_feeds = c.execute("SELECT * FROM feeds").fetchall()
- #c.close()
except:
pass
- # The key of dic is the id of the feed:
# articles[feed_id] = (article_id, article_date, article_title,
# article_link, article_description, article_readed)
# feeds[feed_id] = (nb_article, nb_article_unreaded, feed_image,
@@ -149,6 +145,7 @@ def load_feed():
else:
articles[feed_id].append(article_list)
+
# sort articles by date for each feeds
for rss_feed_id in articles.keys():
articles[rss_feed_id].sort(lambda x,y: compare(y[1], x[1]))
@@ -161,4 +158,4 @@ def load_feed():
c.close()
return (articles, feeds)
- return (articles, feeds)
+ return (articles, feeds) \ No newline at end of file
bgstack15