Ejemplo n.º 1
0
def book_added_weblaunches(api_token):
    bookings = model._load_weblaunch_bookings()

    for chat_id, weblaunch_ids in bookings.iteritems():
        user = model.get_user(chat_id)
        beer_bot = BeerBot(user['username'], user['password'])

        start = beer_bot.get_weblaunch_start()
        if not start:
            return

        for weblaunch_id in weblaunch_ids:
            beer_bot.create_booking(weblaunch_id=int(weblaunch_id), quantity=1)

        model._save_weblaunch_bookings({})
Ejemplo n.º 2
0
def notify_weblaunches(api_token):
    beer_bot = BeerBot(os.environ['BEER_USERNAME'], os.environ['BEER_PASSWORD'])
    telegram_bot = telegram.Bot(api_token)

    start = beer_bot.get_weblaunch_start()
    if not start:
        return

    subscriptions = model._load_weblaunch_subscriptions()

    for chat_id, latest_weblaunch_date in subscriptions.iteritems():
        if start == string_to_datetime(latest_weblaunch_date):
            continue

        send_weblaunch_notification(start, chat_id, telegram_bot)
        subscriptions[chat_id] = datetime_to_string(start)

    model.save_weblaunch_subscriptions(subscriptions)