예제 #1
0
def main(TOKEN, PORT):
    updater = Updater(token=TOKEN, use_context=True)
    dispatcher = updater.dispatcher
    handler(dispatcher)

    logging.basicConfig(
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        level=logging.INFO)

    if DEBUG:
        updater.start_polling()
    else:
        updater.start_webhook(listen="0.0.0.0", port=int(PORT), url_path=TOKEN)
        updater.bot.setWebhook(
            'https://murmuring-refuge-09405.herokuapp.com/' + TOKEN)
예제 #2
0
    def __init__(self, cache_options = None, dev_token = None, attempts = 3):
        """Initialize the DiffBot API client. Parameters are cache options and the
        required developer token.

        Cache options as a dict with key:
            handler:                            memcache or file
            cache_dir:                        if file cache, use cache folder (default tmp)
            memcache_server:            memcache server IP address
            memcache_user:                memcache username

        dev_token is a required developer token

        attempts is the number of http request attempts to make on failure
        """
        if not dev_token:
            dev_token = os.environ.get('DIFFBOT_TOKEN', False)

        if not dev_token:
            raise Exception("Please provide a dev_token")

        self.dev_token = dev_token

        from handlers import handler

        self._http_handle = handler()(cache_options)
예제 #3
0
def processing():
    newJson = request.get_json()
    if "type" in newJson.keys():
        if newJson['type'] == "message_new":
            session = vk.Session()
            api = vk.API(session)
            user_id = newJson['object']['user_id']
            text = newJson['object']['body'].encode("utf8")
            try:
                answer = handlers.handler(text, user_id)
            except:
                answer = " Упс, что-то пошло не так. Ребята с ИУ уже разбираются. Не обижайтесь, это всё таки бета тест. Возможно вы что-то сделали не так, еще раз почитайте команды )  "

#print( answer )
            if answer[0] == 'p':
                api.messages.send(access_token=token,
                                  user_id=str(user_id),
                                  message="Расписание спорткомплекса",
                                  attachment=SPORT_PHOTOS)
            else:
                api.messages.send(access_token=token,
                                  user_id=str(user_id),
                                  message=answer)
            return 'ok'
        elif newJson['type'] == "confirmation":
            return '9f3fba60'
예제 #4
0
  def __init__(self, cache_options = None, dev_token = None, attempts = 3):
    """Initialize the DiffBot API client. Parameters are cache options and the
    required developer token.

    Cache options as a dict with key:
      handler:              memcache or file
      cache_dir:            if file cache, use cache folder (default tmp)
      memcache_server:      memcache server IP address
      memcache_user:        memcache username

    dev_token is a required developer token

    attempts is the number of http request attempts to make on failure
    """
    if not dev_token:
      dev_token = os.environ.get('DIFFBOT_TOKEN', False)

    if not dev_token:
      raise Exception("Please provide a dev token")

    self.dev_token = dev_token

    from handlers import handler

    self._http_handler_class = handler()
    self._http_handle = self._http_handler_class(cache_options)
예제 #5
0
파일: run.py 프로젝트: mikemrm/osie
# TODO decide to keep or remove? means we'd ignore a failed deprov
log.info("wiping disk partitions")
handlers = handlers.Handler(phone_home, log, tinkerbell, statedir)
handlers.wipe(json.loads(resp.JSON))

log.info("running subscribe loop")
while True:
    j = json.loads(resp.JSON)
    # note: do not try to ignore pushes with out state changes, network
    # sometimes comes in after state:provisioning for example
    state = j["state"]
    i = j.get("instance", {"state": ""})
    log.info("context updated", state=state, instance_state=i.get("state", ""))

    handler = handlers.handler(state)
    if handler:
        try:
            exit = handler(j)
            if exit:
                break
        except Exception as e:
            log.exception("handler failed")
            fail(str(e))

    else:
        log.info("no handler for state", state=state)

    log.info("about to monitor")
    try:
        resp = watch.next()
예제 #6
0
parser.add_argument('--max_retries',
                    type=int,
                    default=MAX_RETRIES,
                    help='The number of attempts for upload before failing')
parser.add_argument('--dirpath',
                    type=str,
                    default=DIRPATH,
                    help='Path to the maidsafe directory')
parser.add_argument(
    '--command',
    type=str,
    required=True,
    help='The command you want to run: (upload | download | list)')
parser.add_argument('--filename',
                    type=str,
                    default="",
                    help='The file being requested')

args = parser.parse_args()
args_dict = vars(args)

if not os.path.isdir(args.dirpath):
    os.mkdir(args.dirpath)

if (args.command == 'upload' or args.command == 'download'):
    if args.filename is "":
        print("Incorrect usage: Need the filename")
        os._exit(0)

handler(args_dict)