aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-09-08 23:32:05 +0200
committercedricbonhomme <devnull@localhost>2010-09-08 23:32:05 +0200
commit2a5e7b5e92cc1f5015b029055e85806c10f85308 (patch)
treefd0d304eeb4914ba32f49b8260cdd61cc84c6d97 /utils.py
parentImprovement of the description of articles page. (diff)
downloadnewspipe-2a5e7b5e92cc1f5015b029055e85806c10f85308.tar.gz
newspipe-2a5e7b5e92cc1f5015b029055e85806c10f85308.tar.bz2
newspipe-2a5e7b5e92cc1f5015b029055e85806c10f85308.zip
Articles are now stored in the Python blist high performance data-structure. if blist module not present, simple lists are used.
Diffstat (limited to 'utils.py')
-rwxr-xr-xutils.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/utils.py b/utils.py
index b27f56a5..7f6fd2b0 100755
--- a/utils.py
+++ b/utils.py
@@ -17,6 +17,12 @@ import operator
import urlparse
import calendar
+try:
+ # for high performance on list
+ from blist import *
+except:
+ pass
+
import smtplib
from email.mime.text import MIMEText
@@ -294,6 +300,7 @@ def load_feed():
feed_id = sha1_hash.hexdigest()
if list_of_articles != []:
+ list_of_articles.sort(lambda x,y: compare(y[0], x[0]))
for article in list_of_articles:
sha1_hash.update(article[2].encode('utf-8'))
article_id = sha1_hash.hexdigest()
@@ -311,15 +318,13 @@ def load_feed():
article[2], article[3], article[4], language, article[6]]
if feed_id not in articles:
- articles[feed_id] = [article_list]
+ try:
+ articles[feed_id] = blist([article_list])
+ except Exception:
+ articles[feed_id] = [article_list]
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]))
-
feeds[feed_id] = (len(articles[feed_id]), \
len([article for article in articles[feed_id] \
if article[5]=="0"]), \
bgstack15