Saturday, July 2, 2011

ShoutOut: using google app engine to ping a number of people at the same time

This is the script i used to message to many of my friends at a time

from google.appengine.api import xmpp from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext.webapp import xmpp_handlers user1="%s said:" dirc=[] class XMPPHandler(xmpp_handlers.CommandHandler):     def text_message(self, message=None):         global dirc         #message.reply("yo man")         myname=unicode(message.sender.split('.')[0].lower()) + '.com'         for dir in dirc:          if myname in dir:           for x in dir:            if myname != x:             xmpp.send_message(x,user1 % myname)             xmpp.send_message(x, message.body)     def start_command(self, message=None):         global dirc         dir=message.body.split(' ')[1].split(';')         dirc[len(dirc):]=[dir[0:]]         myname=message.sender.split('.')[0]         for x in dirc[len(dirc)-1]:          xmpp.send_message(x,"chat session started by %s" % myname)          xmpp.send_message(x,"now in session are:")          for y in dirc[len(dirc)-1]:  xmpp.send_message(x,y)     def stop_command(self, message=None):      i=-1      myname=unicode(message.sender.split('.')[0].lower()) + '.com'      for dir in dirc:       i=i+1       if myname in dir:           for x in dir:          xmpp.send_message(x,"Session Stopped")         del dirc[i] application = webapp.WSGIApplication([('/_ah/xmpp/message/chat/', XMPPHandler)],                                      debug=True) def main():     run_wsgi_app(application) if __name__ == "__main__":     main()

Here the Google App Engine acts as a middleman. A sort of chatroom is formed between a number of users and message belonging to a group is relayed to all members of the group.
A sends a message which B and C receive.
A------->App Engine----->B
                             |
                             |
                            V
                     C
A group chat is started by using /start username1;username2;usernameN
It is stopped by /stop
I kinda stopped working on it. A lot of improvements are to be done. One reason I stopped working on it is because Gmail has this thing inbuilt.
Will come up with an explaination soon. Bear with me.

No comments:

Post a Comment