/
robot.py
48 lines (39 loc) · 1.98 KB
/
robot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
#
# mensabot
#
# Copyright (c) 2010, Daniel Gasienica <daniel@gasienica.ch>
# All rights reserved.
#
from google.appengine.ext import webapp
from waveapi import robot
from waveapi import appengine_robot_runner
from util import credentials
from util import feedparser
FEED = 'https://www.gastro-app.ethz.ch/cgi-bin/menuela/feed_2.0_en_11-1.xml'
class CronHandler(webapp.RequestHandler):
robot = None
# override the constructor
def __init__(self, robot):
self.robot = robot
webapp.RequestHandler.__init__(self)
def get(self):
# wave = self.robot.new_wave(domain="googlewave.com", participants=['daniel.gasienica@googlewave.com',
# 'wilee.lai@googlewave.com',
# 'mklausmann5@googlewave.com'])
wave = self.robot.new_wave(domain='googlewave.com', participants=['wilee.lai@googlewave.com'])
d = feedparser.parse(FEED)
wave.title = d.channel.description
for entry in d.entries:
# append markup currently only supports <p>, <div>, <b>, <strong>, <i>, <em>, <u>.
wave.root_blip.append("\n")
wave.root_blip.append_markup("<p><b>%s</b></p><p>%s</p><p> </p>" % (entry.title, entry.description))
self.robot.submit(wave)
if __name__ == '__main__':
assisty = robot.Robot('myRobot',
image_url='http://wilee-python.appspot.com/icon.png',
profile_url='http://wilee-python.appspot.com/')
assisty.set_verification_token_info(credentials.VERIFICATION_TOKEN, credentials.SECURITY_TOKEN)
assisty.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, server_rpc_base=credentials.RPC_BASE)
appengine_robot_runner.run(assisty, debug=True, extra_handlers=[('/web/cron',
lambda: CronHandler(assisty))])