mgebbe@43: #!/usr/bin/env python
mgebbe@43:
mgebbe@43: import urllib2
mgebbe@43: import simplejson
mgebbe@43: import time
mgebbe@43:
mgebbe@43: # SETTINGS
mgebbe@43:
teichmann@49: user = "dive4elements-test"
teichmann@49: url = "http://io.intevation.de/api/user/%s/feed/public" % user
mgebbe@43: verb = "share" # post or share
mgebbe@43: max_posts = 5
mgebbe@43: max_length = 350
mgebbe@43: opacity75 = 20
mgebbe@43: ocacity50 = 10
mgebbe@43:
mgebbe@43: # END SETTINGS
mgebbe@43:
mgebbe@43: output = []
mgebbe@43:
teichmann@49: oa = output.append
mgebbe@43:
teichmann@49: postcount = 1
teichmann@49:
teichmann@49: oa('
')
mgebbe@43:
mgebbe@43: response = urllib2.urlopen(url)
mgebbe@43: data = simplejson.load(response,'utf8')
mgebbe@43:
mgebbe@43: for item in data["items"]:
mgebbe@43:
teichmann@49: # only shares or posts are interesting
teichmann@49: if item["verb"] != verb: continue
mgebbe@43:
teichmann@49: # max_posts
teichmann@49: if postcount > max_posts: break
mgebbe@43:
teichmann@49: try:
teichmann@49: content = item["object"]["content"]
teichmann@49: except KeyError:
teichmann@49: continue
mgebbe@43:
teichmann@49: postcount += 1
teichmann@49: content = content.encode('utf8')
teichmann@49: oa("- ")
teichmann@49:
teichmann@49: if len(content) >= max_length:
teichmann@49: oa(content[:(max_length-opacity75)])
teichmann@49: oa("")
teichmann@49: #oa("")
teichmann@49: oa('')
teichmann@49: oa(content[(max_length-opacity75):(max_length-ocacity50)])
teichmann@49: oa('')
teichmann@49: oa('')
teichmann@49: oa(content[(max_length-ocacity50):(max_length)])
teichmann@49: oa('...')
teichmann@49: else:
teichmann@49: oa(content)
teichmann@49:
teichmann@49: oa('
')
teichmann@49: actor = item["actor"]
teichmann@49: #oa("more...")
teichmann@137: oa(''+actor["displayName"]+'')
teichmann@49: #oa(item["content"])
teichmann@49: if verb == "share":
teichmann@137: oa(' via '+item["object"]["author"]["displayName"]+'
')
teichmann@49: #if verb == "share":
teichmann@49: # oa(' via '+item["object"]["author"]["displayName"]+'')
teichmann@49:
teichmann@49: # 2014-01-03T10:30:02Z
teichmann@49: date = time.strptime(item["updated"],"%Y-%m-%dT%H:%M:%SZ")
teichmann@49: oa(time.strftime(" %d.%m.%Y um %H:%M:%S", date))
teichmann@49: oa('')
teichmann@137: oa('
')
teichmann@49: oa(" ")
teichmann@49:
teichmann@49: oa("
")
teichmann@49: #oa('mehr von '+data["author"]["displayName"]+'' )
teichmann@49: body = ''.join(output)
mgebbe@43:
mgebbe@43: print "Content-Type: text/html;charset=utf-8"
mgebbe@43: print
teichmann@49: print body
mgebbe@43: