Example #1
0
def create_db():
    import os
    if not ('HEROKU' in os.environ):
        db = SqliteDatabase('sender.sqlite')
        db.connect(True)

        db.drop_tables([Account, Subscription, Messenger, AccessToken])
        db.create_tables([Account, Subscription, Messenger, AccessToken])

        vk = Messenger.create(name='VK', cost=200)
        vk.save()

        telegram = Messenger.create(name='Telegram', cost=200)
        telegram.save()

    else:
        init_db()

        db_proxy.connect(True)
        print('CONNECTED')

        db_proxy.create_tables([AdminPage, TargetGroup, UserPage, SenderPage],
                               safe=True)

        print('before AdminPage')
        yuri = AdminPage(vkid=142872618)
        yuri.save()

        print('before db.close()')
        db_proxy.close()

        return 'DB is created!'
Example #2
0
def create_db():
    import os
    if not ('DYNO' in os.environ):
        db = SqliteDatabase('../sender.sqlite')
        db.connect(True)

        db.drop_tables([AdminPage, TargetGroup, UserPage, SenderPage])
        db.create_tables([AdminPage, TargetGroup, UserPage, SenderPage])

        yuri = AdminPage(vkid=142872618)
        yuri.save()
    else:
        init_db()

        db_proxy.connect(True)
        print('CONNECTED')
        # TODO сделать так, чтобы дубликаты не добавлялись
        db_proxy.create_tables([AdminPage, TargetGroup, UserPage, SenderPage],
                               safe=True)

        print('before AdminPage')
        yuri = AdminPage(vkid=142872618)
        yuri.save()

        print('before db.close()')
        db_proxy.close()

        return 'DB is created!'
Example #3
0
def debug_processing(strdata):
    print(strdata)

    data = json.loads(strdata)

    db_proxy.connect(True)
    logger.info('in processing')

    # Вконтакте в своих запросах всегда отправляет поле типа
    if 'type' not in data.keys():
        return 'not vk'

    if data['type'] == 'confirmation':
        return confirmation_token

    elif data['type'] == 'message_new' or data['type'] == 'service_reply':
        logger.info('pulled message: ' + str(data['object']))

        from tools.constants import Messenger
        data['messenger'] = str(Messenger.VK.name)

        session['bot'].reply_to_message(data)
        return 'ok'

    db_proxy.close()
    return 'ok'