Mercurial > dive4elements > website
annotate newsfeed.py @ 114:eb47b2456212
Set x-bit for devel page.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 01 Apr 2014 11:40:28 +0200 |
parents | a9a3c55ef91c |
children | f00a8a8d9225 |
rev | line source |
---|---|
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
2 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
3 import urllib2 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
4 import simplejson |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
5 import time |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
6 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
7 # SETTINGS |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
8 |
49
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
9 user = "dive4elements-test" |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
10 url = "http://io.intevation.de/api/user/%s/feed/public" % user |
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
11 verb = "share" # post or share |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
12 max_posts = 5 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
13 max_length = 350 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
14 opacity75 = 20 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
15 ocacity50 = 10 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
16 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
17 # END SETTINGS |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
18 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
19 output = [] |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
20 |
49
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
21 oa = output.append |
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
22 |
49
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
23 postcount = 1 |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
24 |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
25 oa('<ul style="list-style-type: square; margin-left:-25px;line-height: 23px;">') |
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
26 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
27 response = urllib2.urlopen(url) |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
28 data = simplejson.load(response,'utf8') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
29 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
30 for item in data["items"]: |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
31 |
49
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
32 # only shares or posts are interesting |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
33 if item["verb"] != verb: continue |
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
34 |
49
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
35 # max_posts |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
36 if postcount > max_posts: break |
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
37 |
49
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
38 try: |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
39 content = item["object"]["content"] |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
40 except KeyError: |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
41 continue |
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
42 |
49
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
43 postcount += 1 |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
44 content = content.encode('utf8') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
45 oa("<li>") |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
46 |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
47 if len(content) >= max_length: |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
48 oa(content[:(max_length-opacity75)]) |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
49 oa("<a href="+item["actor"]["url"]+">") |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
50 #oa("<a href="+item["object"]["url"]+">") |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
51 oa('<span style="opacity: 0.75;filter:Alpha(opacity=75)">') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
52 oa(content[(max_length-opacity75):(max_length-ocacity50)]) |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
53 oa('</span>') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
54 oa('<span style="opacity: 0.50;filter:Alpha(opacity=50)">') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
55 oa(content[(max_length-ocacity50):(max_length)]) |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
56 oa('...</span></a>') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
57 else: |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
58 oa(content) |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
59 |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
60 oa('<br>') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
61 actor = item["actor"] |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
62 #oa("<a href="+item["object"]["links"]["self"]["href"]+">more...</a>") |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
63 oa('<span style="font-size:smaller">') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
64 oa('<a href="'+actor["url"]+'">'+actor["displayName"]+'</a>') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
65 #oa(item["content"]) |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
66 if verb == "share": |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
67 oa(' via <a href="'+item["object"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
68 #if verb == "share": |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
69 # oa(' via <a href="'+item["object"]["author"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
70 |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
71 # 2014-01-03T10:30:02Z |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
72 date = time.strptime(item["updated"],"%Y-%m-%dT%H:%M:%SZ") |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
73 oa(time.strftime(" %d.%m.%Y um %H:%M:%S", date)) |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
74 oa('</span>') |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
75 oa("</li>") |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
76 |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
77 oa("</ul>") |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
78 #oa('<a href="'+data["author"]["url"]+'">mehr von '+data["author"]["displayName"]+'</a>' ) |
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
79 body = ''.join(output) |
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
80 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
81 print "Content-Type: text/html;charset=utf-8" |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
82 print |
49
a9a3c55ef91c
Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
44
diff
changeset
|
83 print body |
43
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
84 |