aboutsummaryrefslogtreecommitdiff
path: root/utils.py
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 /utils.py
parentAdded detect_url_errors() function. (diff)
downloadnewspipe-2de2910a2a8311f27fc243cefacb20b601d280b2.tar.gz
newspipe-2de2910a2a8311f27fc243cefacb20b601d280b2.tar.bz2
newspipe-2de2910a2a8311f27fc243cefacb20b601d280b2.zip
Added history page with a tag clouds.
Diffstat (limited to 'utils.py')
-rwxr-xr-xutils.py13
1 files changed, 11 insertions, 2 deletions
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