def main(): db_wrapper.init('188.166.85.96', 27017, None, None) while True: try: try_process_event() except Exception as e: print e finally: time.sleep(5)
def __init__(self): db_wrapper.init("188.166.85.96", 27017, None, None)
for competition in competitions: # print 'Competition: ' # print competition.name() print "%s %s" % (competition.name(), str(competition.start_date())) db_wrapper.Event.add( competition.competition_id(), competition.name(), competition.teams(), competition.start_date() ) event = db_wrapper.Event(competition.competition_id()) if competition.finished(): event.set_score(competition.score()) @staticmethod def get_known_events(): return [event.event_id for event in db_wrapper.Event.get_all()] # known_event_ids = [] # for event in db_wrapper.Event.get_all(): # known_event_ids.append(event.event_id) # return known_event_ids if __name__ == "__main__": db_wrapper.init("188.166.85.96", 27017, None, None) while True: try: YandexSportAPICrawler.crawl() except Exception as e: print e finally: time.sleep(60)
time.sleep(5) def handle_updates(): try: data = flask.request.get_data() update = telebot.types.Update.de_json(data) bot.process_new_messages([update.message]) return '' except Exception as e: print >> sys.stderr, 'Couldn\'t update: {}'.format(e) def run_webhooks(cert, webhook): bot.remove_webhook() bot.set_webhook(url='https://{}:{}{}'.format(webhook['host'], webhook['port'], webhook['url']), certificate=open(cert['public'])) app = flask.Flask(__name__) app.add_url_rule(webhook['url'], 'update', handle_updates, methods=['POST']) app.run(host='0.0.0.0', port=webhook['port'], ssl_context=(cert['public'], cert['private']), debug=False, threaded=True) if __name__ == '__main__': with open('config.json') as config: config = json.load(config) db_wrapper.init(**config) event_notifier_thread = threading.Thread(target=event_notifier, args=(bot, )) event_notifier_thread.start() # bot.polling(True) run_webhooks(config['certificate'], config['webhook']) event_notifier_thread.join()