Mercurial > dive4elements > website
annotate newsfeed.py @ 44:8cc0036041cf
set URL, removed index.psp
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Mon, 10 Mar 2014 17:57:41 +0100 |
parents | 5541d758f62a |
children | a9a3c55ef91c |
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 import sys |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
7 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
8 # SETTINGS |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
9 |
44
8cc0036041cf
set URL, removed index.psp
Mathias Gebbe <mgebbe@intevation.de>
parents:
43
diff
changeset
|
10 url = "http://io.intevation.de/api/user/dive4elements/feed/public" |
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 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
21 postcount = 1 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
22 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
23 output.append( |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
24 '<ul style="list-style-type: square; margin-left:-25px;line-height: 23px;">' |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
25 ) |
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 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
32 # only shares or posts are interesting |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
33 if item["verb"] != verb: continue |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
34 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
35 # max_posts |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
36 if postcount > max_posts: break |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
37 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
38 try: |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
39 content = item["object"]["content"] |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
40 except KeyError: |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
41 continue |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
42 postcount+=1 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
43 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
44 content = content.encode('utf8') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
45 output.append("<li>") |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
46 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
47 if len(content) >= max_length: |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
48 output.append(content[:(max_length-opacity75)]) |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
49 output.append("<a href="+item["actor"]["url"]+">") |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
50 #output.append("<a href="+item["object"]["url"]+">") |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
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>') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
52 else: |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
53 output.append(content) |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
54 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
55 output.append('<br>') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
56 #output.append("<a href="+item["object"]["links"]["self"]["href"]+">more...</a>") |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
57 output.append('<span style="font-size:smaller">') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
58 output.append('<a href="'+item["actor"]["url"]+'">'+item["actor"]["displayName"]+'</a>') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
59 #output.append(item["content"]) |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
60 if verb == "share": output.append(' via <a href="'+item["object"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
61 #if verb == "share": output.append(' via <a href="'+item["object"]["author"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
62 # 2014-01-03T10:30:02Z |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
63 date=time.strptime(item["updated"],"%Y-%m-%dT%H:%M:%SZ") |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
64 output.append(" "+(time.strftime("%d.%m.%Y um %H:%M:%S", date))) |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
65 output.append('</span>') |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
66 output.append("</li>") |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
67 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
68 output.append("</ul>") |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
69 #output.append('<a href="'+data["author"]["url"]+'">mehr von '+data["author"]["displayName"]+'</a>' ) |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
70 s = ''.join(output) |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
71 |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
72 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
|
73 print |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
74 print s |
5541d758f62a
Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff
changeset
|
75 |