Example #1
0
  def stop_command(self, message=None):
    """process /stop command"""
    # message was /stop ...
    # delete from database
    user,trigger,desc=parse_user_command(message)
    stats=Statistics.all().get()
    stats.chats+=1

    if trigger.lower()=='all':
      to_be_deleted=[]
      for result in Trigger.all().filter("user ="******"user ="******"trigger =",trigger).get()
      if result:
        result.delete()
        stats.row-=1
      if not Trigger.all().filter("user ="******"stop_command: %s, [%s]" % (user,trigger))
    message.reply(STOP_MSG % trigger )
    stats.put()
Example #2
0
 def text_message(self, message=None):
   # called if message doesnt start with /
   # Show help text
   stats=Statistics.all().get()
   stats.chats+=1;
   stats.put()
   message.reply(HELP_MSG)
Example #3
0
 def show_command(self, message=None):
   """process /show command"""
   # send back list of current triggers
   user,trigger,desc=parse_user_command(message)
   stats=Statistics.all().get()
   stats.chats+=1;
   results_list="Current Triggers:\n"
   for result in Trigger.all().filter("user ="******"%s:%s\n"%(result.trigger,result.desc)
   logging.info("show_command: %s" % (user))
   message.reply(results_list)
   stats.put()
Example #4
0
  def start_command(self, message=None):
    """process /start command"""
    # add to database and reply
    user,trigger,desc=parse_user_command(message)
    stats=Statistics.all().get()
    stats.chats+=1;
    #total number of allowed rows
    if stats.row_total >= MAX_ROWS:
      message.reply(MAX_ROWS_MSG)
      logging.info("start_command: Max rows reached %s" % (user))
      return
    #check number of triggers user has already
    if Trigger.all().filter("user ="******"start_command: too many triggers %s" % (user))
      return
    #limits on trigger length
    if len(trigger)<TRIGGER_LEN[0] or len(trigger)>TRIGGER_LEN[1]:
      message.reply(TRIGGER_LEN_MSG % (TRIGGER_LEN[0],TRIGGER_LEN[1]))
      return

    # limits on desc length
    desc=desc[0:DESC_LEN]

    result=Trigger.all().filter("user ="******"trigger =",trigger).get()
    if result:
      if result.desc != desc:
        result.desc=desc
        result.put()
    else:
      if not Trigger.all().filter("user ="******"start_command: %s, [%s] %s" % (user,trigger,desc))
    message.reply(START_MSG % (self.request.host_url,trigger,desc,trigger))
    stats.put()
Example #5
0
def trigger_post(trigger='xyz'):
    """Handle POST-ed data to http://<url>/trigger/<trigger_id>"""
# save updated record and put them all at once
#http://googleappengine.blogspot.com.au/2009/06/10-things-you-probably-didnt-know-about.html
    updated=[]
    now=datetime.datetime.fromtimestamp(time.time())
    then=now-NOTIFY_INTERVAL
    n=Statistics.all().get()
    n.triggers+=1
    for result in Trigger.all().filter("trigger =",trigger):
#dont notify user more often than NOTIFY_INTERVAL
      if (result.last_notify<=then) and (not result.paused):
        logging.info("send_message: %s: %s [%s]" % (result.user.address,result.desc,trigger))
        xmpp.send_message(result.user.address, '%s [%s]' %(result.desc,trigger)  )
        result.last_notify=now
        updated.append(result)
        n.notifies+=1
    db.put(updated)
    n.put()
    return ""
Example #6
0
 def pause_command(self, message=None):
   """process /pause command"""
   #set suspend flag
   user,trigger,desc=parse_user_command(message)
   stats=Statistics.all().get()
   stats.chats+=1;
   if trigger.lower()=='all':
     to_be_paused=[]
     for result in Trigger.all().filter("user ="******"paused =",False):
       result.paused=True
       to_be_paused.append(result)
     db.put(to_be_paused)
   else:
     result=Trigger.all().filter("user ="******"trigger =",trigger).filter("paused =",False).get()
     if result:
       result.paused=True
       result.put()
   logging.info("pause_command: %s, [%s]" % (user,trigger))
   message.reply(PAUSE_MSG % trigger )
   stats.put()
Example #7
0
def error404(error):
  n=Statistics.all().get()
  n.probes+=1
  n.put()
  return ''
Example #8
0
import logging
import datetime
import time
from google.appengine.api import xmpp
#from google.appengine.ext.webapp import xmpp_handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
#from google.appengine.ext.webapp import util
from bottle import Bottle, run,static_file
from datastore import Trigger, Statistics
from google.appengine.ext import db

NOTIFY_INTERVAL=datetime.timedelta(hours=8)
#NOTIFY_INTERVAL=datetime.timedelta(minutes=2)

if not Statistics.all().get():
  #create the record to hold the stats
  n=Statistics() 
  n.users=1
  n.triggers=0
  n.notifies=0
  n.probes=0
  n.chats=0
  n.row_total=0
  n.put()
#

app = Bottle()

                      
#http://bottlepy.org/docs/stable/tutorial.html#request-routing
Example #9
0
 def unhandled_command(self, message=None):
   """process undefined /xxx command"""
   stats=Statistics.all().get()
   stats.chats+=1;
   stats.put()
   message.reply(HELP_MSG)