Mercurial > dive4elements > website
view index.psp @ 38:c4f1df6e88b0
Renamed ssrodio to scripts
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 05 Mar 2014 16:57:57 +0100 |
parents | b775179be3d4 |
children |
line wrap: on
line source
<% import requests import urllib2 import simplejson import time # SETTINGS tmpl = "/var/lib/gforge/chroot/home/groups/dive4elements/htdocs/index.html" url = "https://io.intevation.de/api/user/dive4elements/feed/public" #url = "https://io.intevation.de/api/user/Intevation/feed/public" verb = "share" # post or share max_posts = 5 max_length = 300 opacity75 = 20 ocacity50 = 10 # END SETTINGS with open (tmpl, "r") as myfile: template=myfile.read() req.content_type = "text/html; charset=UTF-8" output = [] postcount = 1 output.append( '<ul style="list-style-type: square; margin-left:-25px;line-height: 23px;">' ) response = urllib2.urlopen(url) data = simplejson.load(response,'utf8') for item in data["items"]: # only shares or posts are interesting if item["verb"] != verb: continue # max_posts if postcount > max_posts: break try: content = item["object"]["content"] except KeyError: continue postcount+=1 content = content.encode('utf-8') output.append("<li>") if len(content) >= max_length: output.append(content[:(max_length-opacity75)]) output.append("<a href="+item["actor"]["url"]+">") #output.append("<a href="+item["object"]["url"]+">") output.append('<span style="opacity: 0.75;filter:Alpha(opacity=75)">' + content[(max_length-opacity75):(max_length-ocacity50)] + '</span>' + '<span style="opacity: 0.50;filter:Alpha(opacity=50)">' + content[(max_length-ocacity50):(max_length)] + '...</span></a>') else: output.append(content) output.append('<br>') #output.append("<a href="+item["object"]["links"]["self"]["href"]+">more...</a>") output.append('<span style="font-size:smaller">') output.append('<a href="'+item["actor"]["url"]+'">'+item["actor"]["displayName"]+'</a>') #output.append(item["content"]) if verb == "share": output.append(' via <a href="'+item["object"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>') #if verb == "share": output.append(' via <a href="'+item["object"]["author"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>') # 2014-01-03T10:30:02Z date=time.strptime(item["updated"],"%Y-%m-%dT%H:%M:%SZ") output.append(" "+(time.strftime("%d.%m.%Y um %H:%M:%S", date))) output.append('</span>') output.append("</li>") output.append("</ul>") #output.append('<a href="'+data["author"]["url"]+'">mehr von '+data["author"]["displayName"]+'</a>' ) str = ''.join(output) template = template.replace('{newsfeed}',str) req.write(template) %>