From 2de2910a2a8311f27fc243cefacb20b601d280b2 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Fri, 3 Sep 2010 10:58:37 +0200 Subject: Added history page with a tag clouds. --- css/style.css | 2 +- pyAggr3g470r.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ utils.py | 13 +++++++++-- 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/css/style.css b/css/style.css index 41a25d99..5a649c39 100755 --- a/css/style.css +++ b/css/style.css @@ -145,7 +145,7 @@ hr { } /* Navigation bars */ -.nav_container { position:fixed; top:200px; right:60px; margin:0px; padding:0px; white-space:nowrap; z-index:11; clear:both;} +.nav_container { position:fixed; top:220px; right:60px; margin:0px; padding:0px; white-space:nowrap; z-index:11; clear:both;} .nav_container.horizontal { position:absolute; white-space:normal; z-index:25; width:670px; } .nav_container.horizontal div { float:right; padding-right:10px; } diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 08250b87..aed658c8 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -11,8 +11,11 @@ import os import time import sqlite3 import cherrypy +import calendar import threading +from collections import Counter + import utils import feedgetter import PyQRNative @@ -151,6 +154,7 @@ class Root: """ html = """
\n""" html += """Management
\n""" + html += """History
\n""" html += """Fetch all feeds
\n""" html += """Mark articles as read\n""" html += """
\n""" + + if querystring == "all": + html += "

Chose a year


\n" + if "year" in querystring: + the_year = querystring.split('-')[0].split(':')[1] + if "month" in querystring: + the_month = querystring.split('-')[1].split(':')[1] + html += "

Articles of "+ calendar.month_name[int(the_month)] + \ + ", "+ the_year +".


\n" + + timeline = Counter() + for rss_feed_id in self.feeds.keys(): + for article in self.articles[rss_feed_id]: + + if querystring == "all": + timeline[article[1].encode('utf-8').split(' ')[0].split('-')[0]] += 1 + + elif querystring[:4] == "year": + + if article[1].encode('utf-8').split(' ')[0].split('-')[0] == the_year: + timeline[article[1].encode('utf-8').split(' ')[0].split('-')[1]] += 1 + + if "month" in querystring: + if article[1].encode('utf-8').split(' ')[0].split('-')[1] == the_month: + if article[5] == "0": + # not readed articles are in bold + not_read_begin = "" + not_read_end = "" + else: + not_read_begin = "" + not_read_end = "" + + if article[7] == "1": + like = """ """ + else: + like = "" + + html += article[1].encode('utf-8') + \ + " - " + not_read_begin + \ + """%s""" % \ + (rss_feed_id, article[0].encode('utf-8'), \ + utils.clear_string(article[2].encode('utf-8'))) + \ + not_read_end + like + \ + "
\n" + + if querystring == "all": + query = "year" + elif "year" in querystring: + query = "year:" + the_year + "-month" + if "month" not in querystring: + html += '
' + \ + utils.tag_cloud([(elem, timeline[elem]) for elem in timeline.keys()], \ + query) + '
' + + html += "
\n" + html += htmlfooter + return html + + history.exposed = True + + def plain_text(self, target): """ Display an article in plain text (without HTML tags). diff --git a/utils.py b/utils.py index 7e7edfde..b27f56a5 100755 --- a/utils.py +++ b/utils.py @@ -15,6 +15,7 @@ import hashlib import sqlite3 import operator import urlparse +import calendar import smtplib from email.mime.text import MIMEText @@ -120,14 +121,22 @@ def top_words(dic_articles, n=10, size=5): words[word] += 1 return words.most_common(n) -def tag_cloud(tags): +def tag_cloud(tags, query="word_count"): """ Generates a tags cloud. """ tags.sort(key=operator.itemgetter(0)) - return ' '.join([('%s\n' % \ + if query == "word_count": + return ' '.join([('%s\n' % \ (min(1 + count * 7 / max([tag[1] for tag in tags]), 7), word, count, word)) \ for (word, count) in tags]) + if query == "year": + return ' '.join([('%s\n' % \ + (min(1 + count * 7 / max([tag[1] for tag in tags]), 7), query, word, count, word)) \ + for (word, count) in tags]) + return ' '.join([('%s\n' % \ + (min(1 + count * 7 / max([tag[1] for tag in tags]), 7), query, word, count, calendar.month_name[int(word)])) \ + for (word, count) in tags]) def send_mail(mfrom, mto, feed_title, message): """Send the warning via mail -- cgit