#!/usr/bin/env python
# -*- coding: utf-8 -*-

import cgi
import random
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from MessageBuilder import *
from PushConnection import *

class MainHandler(webapp.RequestHandler):
    def post(self):
        M = MessageBuilder()
        msg = cgi.escape(self.request.body)
        if msg == 'hej': M.addBBcode('[b]Hej GG: [color=ffaa00]%s[/color][/b]' % (int(self.request.get('from'))))
        elif msg == 'opis':
            opis = random.randint(1, 99)
            M.addBBcode('[color=00ff00]Ustawiam opis na: [i]%s[/i][/color]' % (opis))
            P = PushConnection(42990004, 'botgg42990004@gmail.com', 'qNihAdYXPu48TXig')
            P.setStatus(str(opis), STATUS_AWAY)
        else: M.addBBcode('Napisz: [u]hej[/u] lub [u]opis[/u]')
        self.response.out.write(M.reply(self))

application = webapp.WSGIApplication([('/', MainHandler)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()