aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2010-09-03 10:58:37 +0200
committercedricbonhomme <devnull@localhost>2010-09-03 10:58:37 +0200
commit2de2910a2a8311f27fc243cefacb20b601d280b2 (patch)
treec85f0d2d4a8ffa046448df446ca296f3d06b11f0
parentAdded detect_url_errors() function. (diff)
downloadnewspipe-2de2910a2a8311f27fc243cefacb20b601d280b2.tar.gz
newspipe-2de2910a2a8311f27fc243cefacb20b601d280b2.tar.bz2
newspipe-2de2910a2a8311f27fc243cefacb20b601d280b2.zip
Added history page with a tag clouds.
-rwxr-xr-xcss/style.css2
-rwxr-xr-xpyAggr3g470r.py72
-rwxr-xr-xutils.py13
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 = """<div class="right inner">\n"""
html += """<a href="/management/">Management</a><br />\n"""
+ html += """<a href="/history/">History</a><br />\n"""
html += """<a href="/fetch/">Fetch all feeds</a><br />\n"""
html += """<a href="/mark_as_read/All:">Mark articles as read</a>\n"""
html += """<form method=get action="/q/"><input type="text" name="querystring" value=""><input
@@ -573,6 +577,74 @@ class Root:
language.exposed = True
+ def history(self, querystring="all"):
+ """
+ History
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">\n"""
+
+ if querystring == "all":
+ html += "<h1>Chose a year</h1></br >\n"
+ if "year" in querystring:
+ the_year = querystring.split('-')[0].split(':')[1]
+ if "month" in querystring:
+ the_month = querystring.split('-')[1].split(':')[1]
+ html += "<h1>Articles of "+ calendar.month_name[int(the_month)] + \
+ ", "+ the_year +".</h1><br />\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 = "<b>"
+ not_read_end = "</b>"
+ else:
+ not_read_begin = ""
+ not_read_end = ""
+
+ if article[7] == "1":
+ like = """ <img src="/css/img/heart.png" title="I like this article!" />"""
+ else:
+ like = ""
+
+ html += article[1].encode('utf-8') + \
+ " - " + not_read_begin + \
+ """<a href="/description/%s:%s" rel="noreferrer" target="_blank">%s</a>""" % \
+ (rss_feed_id, article[0].encode('utf-8'), \
+ utils.clear_string(article[2].encode('utf-8'))) + \
+ not_read_end + like + \
+ "<br />\n"
+
+ if querystring == "all":
+ query = "year"
+ elif "year" in querystring:
+ query = "year:" + the_year + "-month"
+ if "month" not in querystring:
+ html += '<div style="width: 35%; overflow:hidden; text-align: justify">' + \
+ utils.tag_cloud([(elem, timeline[elem]) for elem in timeline.keys()], \
+ query) + '</div>'
+
+ html += "<hr />\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([('<font size="%d"><a href="/q/?querystring=%s" title="Count: %s">%s</a></font>\n' % \
+ if query == "word_count":
+ return ' '.join([('<font size="%d"><a href="/q/?querystring=%s" title="Count: %s">%s</a></font>\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([('<font size="%d"><a href="/history/?querystring=%s:%s" title="Count: %s">%s</a></font>\n' % \
+ (min(1 + count * 7 / max([tag[1] for tag in tags]), 7), query, word, count, word)) \
+ for (word, count) in tags])
+ return ' '.join([('<font size="%d"><a href="/history/?querystring=%s:%s" title="Count: %s">%s</a></font>\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
bgstack15