Mercurial > dive4elements > website
comparison newsfeed.py @ 43:5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Mon, 10 Mar 2014 17:47:07 +0100 |
parents | |
children | 8cc0036041cf |
comparison
equal
deleted
inserted
replaced
42:3fe0a15a02d0 | 43:5541d758f62a |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import urllib2 | |
4 import simplejson | |
5 import time | |
6 import sys | |
7 | |
8 # SETTINGS | |
9 | |
10 url = "http://goldenrod.rgb/api/user/dive4elements/feed/public" | |
11 verb = "share" # post or share | |
12 max_posts = 5 | |
13 max_length = 350 | |
14 opacity75 = 20 | |
15 ocacity50 = 10 | |
16 | |
17 # END SETTINGS | |
18 | |
19 output = [] | |
20 | |
21 postcount = 1 | |
22 | |
23 output.append( | |
24 '<ul style="list-style-type: square; margin-left:-25px;line-height: 23px;">' | |
25 ) | |
26 | |
27 response = urllib2.urlopen(url) | |
28 data = simplejson.load(response,'utf8') | |
29 | |
30 for item in data["items"]: | |
31 | |
32 # only shares or posts are interesting | |
33 if item["verb"] != verb: continue | |
34 | |
35 # max_posts | |
36 if postcount > max_posts: break | |
37 | |
38 try: | |
39 content = item["object"]["content"] | |
40 except KeyError: | |
41 continue | |
42 postcount+=1 | |
43 | |
44 content = content.encode('utf8') | |
45 output.append("<li>") | |
46 | |
47 if len(content) >= max_length: | |
48 output.append(content[:(max_length-opacity75)]) | |
49 output.append("<a href="+item["actor"]["url"]+">") | |
50 #output.append("<a href="+item["object"]["url"]+">") | |
51 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>') | |
52 else: | |
53 output.append(content) | |
54 | |
55 output.append('<br>') | |
56 #output.append("<a href="+item["object"]["links"]["self"]["href"]+">more...</a>") | |
57 output.append('<span style="font-size:smaller">') | |
58 output.append('<a href="'+item["actor"]["url"]+'">'+item["actor"]["displayName"]+'</a>') | |
59 #output.append(item["content"]) | |
60 if verb == "share": output.append(' via <a href="'+item["object"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>') | |
61 #if verb == "share": output.append(' via <a href="'+item["object"]["author"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>') | |
62 # 2014-01-03T10:30:02Z | |
63 date=time.strptime(item["updated"],"%Y-%m-%dT%H:%M:%SZ") | |
64 output.append(" "+(time.strftime("%d.%m.%Y um %H:%M:%S", date))) | |
65 output.append('</span>') | |
66 output.append("</li>") | |
67 | |
68 output.append("</ul>") | |
69 #output.append('<a href="'+data["author"]["url"]+'">mehr von '+data["author"]["displayName"]+'</a>' ) | |
70 s = ''.join(output) | |
71 | |
72 print "Content-Type: text/html;charset=utf-8" | |
73 print | |
74 print s | |
75 |