view newsfeed.py @ 144:d8de679055c6

Don't mention file size, link download page on Wald.
author Tom Gottfried <tom@intevation.de>
date Fri, 04 Apr 2014 11:02:01 +0200
parents e209a6446e88
children 651669645c42
line wrap: on
line source
#!/usr/bin/env python

import urllib2
import simplejson
import time

# SETTINGS

user       = "dive4elements-test"
url        = "http://io.intevation.de/api/user/%s/feed/public" % user
verb       = "share" # post or share
max_posts  = 5
max_length = 350
opacity75  = 20
ocacity50  = 10

# END SETTINGS

output = []

oa = output.append

postcount = 1

oa('<ul style="list-style-type: square; margin-left:-25px;line-height: 23px;">')

response = urllib2.urlopen(url)
data = simplejson.load(response,'utf8')

for item in data["items"]:

    # only shares or posts are interesting
    if item["verb"] != verb: continue

    # max_posts
    if postcount > max_posts: break

    try:
        content = item["object"]["content"]
    except KeyError:
        continue

    postcount += 1
    content = content.encode('utf8')
    oa("<li>")
    oa('<div style="margin-bottom:1em">')

    if len(content) >= max_length:
        oa(content[:(max_length-opacity75)])
        oa("<a href="+item["actor"]["url"]+">")
        oa('<span style="opacity: 0.75;filter:Alpha(opacity=75)">')
        oa(content[(max_length-opacity75):(max_length-ocacity50)])
        oa('</span>')
        oa('<span style="opacity: 0.50;filter:Alpha(opacity=50)">')
        oa(content[(max_length-ocacity50):(max_length)])
        oa('...</span></a>')
    else:
        oa(content)

    actor = item["actor"]
    oa('<div style="font-size:smaller">')
    oa('<a href="%s">%s</a>' % (actor["url"], actor["displayName"]+'</a>'))
    if verb == "share":
        oa(' via <a href="%s">%s</a><br>' % (item["object"]["url"], item["object"]["author"]["displayName"]))

    date = time.strptime(item["updated"],"%Y-%m-%dT%H:%M:%SZ")
    oa(time.strftime(" %d.%m.%Y um %H:%M:%S", date))
    oa('</div>')
    oa('</div>')
    oa("</li>")

oa("</ul>")
body = ''.join(output)

print "Content-Type: text/html;charset=utf-8"
print
print body
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)