annotate newsfeed.py @ 172:9416a80b680b

Remove hidden redirect to abandoned project
author Tom Gottfried <tom@intevation.de>
date Thu, 15 Nov 2018 16:03:58 +0100
parents 651669645c42
children
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
160
651669645c42 User dive4elements pump.io user.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 141
diff changeset
9 user = "dive4elements"
49
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>")
140
6fdb28c3872c Only 1m after feed item.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 139
diff changeset
46 oa('<div style="margin-bottom:1em">')
49
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
47
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
48 if len(content) >= max_length:
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
49 oa(content[:(max_length-opacity75)])
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
50 oa("<a href="+item["actor"]["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 actor = item["actor"]
138
c791f4e9be39 More tweaks in newsfeed output.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 137
diff changeset
61 oa('<div style="font-size:smaller">')
c791f4e9be39 More tweaks in newsfeed output.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 137
diff changeset
62 oa('<a href="%s">%s</a>' % (actor["url"], actor["displayName"]+'</a>'))
49
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
63 if verb == "share":
138
c791f4e9be39 More tweaks in newsfeed output.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 137
diff changeset
64 oa(' via <a href="%s">%s</a><br>' % (item["object"]["url"], item["object"]["author"]["displayName"]))
49
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
65
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
66 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
67 oa(time.strftime(" %d.%m.%Y um %H:%M:%S", date))
138
c791f4e9be39 More tweaks in newsfeed output.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 137
diff changeset
68 oa('</div>')
139
e17f0122ca94 Another div around news items.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 138
diff changeset
69 oa('</div>')
49
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
70 oa("</li>")
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
71
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
72 oa("</ul>")
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
73 body = ''.join(output)
43
5541d758f62a Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
74
5541d758f62a Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
75 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
76 print
49
a9a3c55ef91c Made CGI feed script more readable.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 44
diff changeset
77 print body
43
5541d758f62a Remove PSP, Added SSI, Added newsfeed.py for include
Mathias Gebbe <mgebbe@intevation.de>
parents:
diff changeset
78
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)