annotate index.psp @ 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 b775179be3d4
children
rev   line source
31
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
1 <%
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
2 import requests
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
3 import urllib2
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
4 import simplejson
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
5 import time
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
6
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
7
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
8 # SETTINGS
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
9
32
960c044010e5 Activate Python Server Pages within .htaccess
Mathias Gebbe <mgebbe@intevation.de>
parents: 31
diff changeset
10 tmpl = "/var/lib/gforge/chroot/home/groups/dive4elements/htdocs/index.html"
31
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
11 url = "https://io.intevation.de/api/user/dive4elements/feed/public"
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
12 #url = "https://io.intevation.de/api/user/Intevation/feed/public"
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
13 verb = "share" # post or share
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
14 max_posts = 5
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
15 max_length = 300
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
16 opacity75 = 20
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
17 ocacity50 = 10
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
18
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
19 # END SETTINGS
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
20
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
21 with open (tmpl, "r") as myfile:
34
b775179be3d4 RewriteRule for index.html and changed logo-link to "/"
Mathias Gebbe <mgebbe@intevation.de>
parents: 32
diff changeset
22 template=myfile.read()
31
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
23
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
24 req.content_type = "text/html; charset=UTF-8"
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
25 output = []
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
26
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
27 postcount = 1
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
28
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
29 output.append(
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
30 '<ul style="list-style-type: square; margin-left:-25px;line-height: 23px;">'
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
31 )
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
32
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
33 response = urllib2.urlopen(url)
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
34 data = simplejson.load(response,'utf8')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
35
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
36 for item in data["items"]:
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
37
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
38 # only shares or posts are interesting
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
39 if item["verb"] != verb: continue
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
40
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
41 # max_posts
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
42 if postcount > max_posts: break
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
43
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
44 try:
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
45 content = item["object"]["content"]
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
46 except KeyError:
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
47 continue
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
48 postcount+=1
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
49
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
50 content = content.encode('utf-8')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
51 output.append("<li>")
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
52
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
53 if len(content) >= max_length:
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
54 output.append(content[:(max_length-opacity75)])
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
55 output.append("<a href="+item["actor"]["url"]+">")
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
56 #output.append("<a href="+item["object"]["url"]+">")
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
57 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>')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
58 else:
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
59 output.append(content)
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
60
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
61 output.append('<br>')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
62 #output.append("<a href="+item["object"]["links"]["self"]["href"]+">more...</a>")
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
63 output.append('<span style="font-size:smaller">')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
64 output.append('<a href="'+item["actor"]["url"]+'">'+item["actor"]["displayName"]+'</a>')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
65 #output.append(item["content"])
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
66 if verb == "share": output.append(' via <a href="'+item["object"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
67 #if verb == "share": output.append(' via <a href="'+item["object"]["author"]["url"]+'">'+item["object"]["author"]["displayName"]+'</a>')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
68 # 2014-01-03T10:30:02Z
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
69 date=time.strptime(item["updated"],"%Y-%m-%dT%H:%M:%SZ")
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
70 output.append(" "+(time.strftime("%d.%m.%Y um %H:%M:%S", date)))
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
71 output.append('</span>')
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
72 output.append("</li>")
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
73
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
74 output.append("</ul>")
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
75 #output.append('<a href="'+data["author"]["url"]+'">mehr von '+data["author"]["displayName"]+'</a>' )
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
76
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
77 str = ''.join(output)
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
78 template = template.replace('{newsfeed}',str)
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
79
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
80 req.write(template)
c66f4b393d15 Added index.php for Python Server Pages
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
81 %>
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)