示例#1
0
def main():
    """Handle command line arguments."""
    # CHITS SMS code from Bowei Du
    debug_level = logging.INFO
    config_file = '-'
    test_mode = False
    FORMAT = "%(asctime)-15s:%(levelname)-3s:%(name)-8s %(message)s"
    
    logging.basicConfig(level=debug_level, format = FORMAT)
    opts, args = getopt.getopt(sys.argv[1:], 'hdtc:', ['help', 'debug', 'config-file=', 'test'])
    
    for o, a in opts:
        if o in ('-h', '--help'):
            print help()
            sys.exit(0)
        elif o in ('-d', '--debug'):
            debug_level = logging.DEBUG
        elif o in ('-c', '--config-file'):
            config_file = a.split(':')
        elif o in ('-t', '--test'):
            test_mode = True
    
    cfg = get_config(*config_file)
    smsfile = args[0]
    if not os.path.exists(smsfile):
        raise Exception("Can't find smsfile %s" % smsfile)
    smstext = open(smsfile, 'r').read()
    
    x = Reader(cfg)
    x.run(smstext, test_mode)
示例#2
0
 def process(self, contact, headers, text_content, attachments):
     if self.test_mode:
         contact = self.get_reply_addr(headers, contact)
         if contact:
             self.respond_to_msg(contact, headers, text_content, attachments)
         return
     
     keyword = headers['keyword']
     if keyword == 'default':
         text_content = self.key_default(get_config('chits','main.conf'), contact)
     
     log.debug('\n%s\n%s\n%s\n%s' % (contact, headers, text_content, attachments))
     self.respond_to_msg(contact, headers, text_content, attachments)