Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Cherokee: commits

[3697] web/widgets/render-twitter.py: New widget for the website

 

 

Cherokee commits RSS feed   Index | Next | Previous | View Threaded


cherokee at cherokee-project

Oct 13, 2009, 2:50 PM

Post #1 of 1 (97 views)
Permalink
[3697] web/widgets/render-twitter.py: New widget for the website

Revision: 3697
http://svn.cherokee-project.com/changeset/3697
Author: taher
Date: 2009-10-13 23:50:48 +0200 (Tue, 13 Oct 2009)

Log Message:
-----------
New widget for the website

Added Paths:
-----------
web/widgets/render-twitter.py

Added: web/widgets/render-twitter.py
===================================================================
--- web/widgets/render-twitter.py (rev 0)
+++ web/widgets/render-twitter.py 2009-10-13 21:50:48 UTC (rev 3697)
@@ -0,0 +1,47 @@
+import re
+import json
+import urllib
+from dateutil.parser import parse
+
+LIMIT = 4
+URL = "http://twitter.com/statuses/user_timeline/webserver.json?count=%d" % LIMIT
+OUTPUT = "dynamic/cherokee-tweets.html"
+URL_RE = '((https?|s?ftp|ssh)://[^"\s\<\>]*[^.,;">\:\s\<\>\)\]\!])'
+
+def to_url(url):
+ url = url.group(0)
+ return '<a href="%s">%s</a>' % (url,url)
+
+# Fetch and parse
+#
+text = urllib.urlopen(URL).read()
+data = json.loads(text)
+
+# Generate content
+#
+rc = re.compile(URL_RE)
+content = ''
+from pprint import pprint
+
+for entry in data:
+ pprint(entry)
+ date = str(parse(entry['created_at'])).split('+')[0]
+ tweet = rc.sub(to_url, entry['text'])
+
+ # Tidy up
+ #if len(tweet) > 45:
+ # tweet = tweet[:45] + " .."
+
+ content += tweet
+ content += '<div class="latest-date"><b>%s</b></div>' % date
+ content += '\n'
+
+# Output
+#
+if not content:
+ print "ERROR: Could not build HTML: No content."
+ raise SystemExit
+
+f = open (OUTPUT, 'w+')
+f.write (content.encode('utf-8'))
+f.close()

Cherokee commits RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.