diff options
author | cedricbonhomme <devnull@localhost> | 2010-04-16 21:10:11 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-04-16 21:10:11 +0200 |
commit | 3a6dfd358ded4c26998c86e2a76d34f337c237f8 (patch) | |
tree | 185fc1934728685141a6a90b677565eafffe6c41 | |
parent | Added tags cloud. (diff) | |
download | newspipe-3a6dfd358ded4c26998c86e2a76d34f337c237f8.tar.gz newspipe-3a6dfd358ded4c26998c86e2a76d34f337c237f8.tar.bz2 newspipe-3a6dfd358ded4c26998c86e2a76d34f337c237f8.zip |
Minor enhancement.
-rwxr-xr-x | utils.py | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -16,6 +16,7 @@ except: IMPORT_ERROR.append("pylab") import sqlite3 import hashlib +import operator import smtplib from email.mime.text import MIMEText @@ -97,9 +98,10 @@ def tag_cloud(tags): """ Generates a tags cloud. """ - tags.sort(lambda x,y: cmp(x[0], y[0])) - return ' '.join([('<font size="%d"><a href="/q/?querystring=%s">%s</a></font>' % \ - (min(1+p*7/max([tag[1] for tag in tags]), 7), x, x)) for (x, p) in tags]) + tags.sort(key=operator.itemgetter(0)) + return ' '.join([('<font size="%d"><a href="/q/?querystring=%s">%s</a></font>\n' % \ + (min(1 + count * 7 / max([tag[1] for tag in tags]), 7), word, word)) \ + for (word, count) in tags]) def create_histogram(words, file_name="./var/histogram.png"): """ |