Esempio n. 1
0
def insert_premise(cid):
    db = dbaccess.SQLka()
    fields = []
    fields.append(('building_id', shelf[str(cid)]['building_id']))
    fields.append(('floor', shelf[str(cid)]['floor']))
    fields.append(('square', shelf[str(cid)]['square']))
    fields.append(
        ('type_of_finish', dbaccess.id_str(shelf[str(cid)]['finish'])))
    fields.append(
        ('premise_type', dbaccess.id_str(shelf[str(cid)]['premise_type'])))
    fields.append(
        ('year_of_finish', dbaccess.id_str(shelf[str(cid)]['year_of_finish'])))
    fields.append(('rooms', shelf[str(cid)]['rooms']))
    fields.append(('water_closets', shelf[str(cid)]['water_closets']))
    try:
        db.insert('premises', fields)
    except:
        bot.send_message(
            cid, text="Введены некорректные данные. Попробуйте ещё раз")
        get_premise(cid)
    prems = db.select(fields=['premise_id'],
                      tables=[('Premises', 'premises')],
                      constraints=[(f[0], dbaccess.eq(f[1])) for f in fields])
    print(prems)
    shelf[str(cid)] = {
        'premise_id': prems[0][0],
        'seller_id': shelf[str(cid)]['seller_id']
    }
    db.close()
    sell_menu(cid)
Esempio n. 2
0
def get_street(message):
    if message.text == '/end':
        return
    cid = message.chat.id
    db = dbaccess.SQLka()
    streets = db.select(fields=['street'],
                        tables=[('Buildings', 'buildings')],
                        constraints=[('street', dbaccess.like(message.text))],
                        modifyers=['DISTINCT'])
    db.close()
    print(streets)
    if len(streets) > 1:
        # TODO Add keyboard
        msg = bot.send_message(
            message.chat.id, """
        Укажите более точное название улицы
        """)
        bot.register_next_step_handler(msg, get_street)
        return
    if len(streets) == 0:
        bot.send_message(cid,
                         text="""
        К сожалению, адрес не найден. Попробуй ещё раз! 
        """)
        get_building(cid)
        return
    shelf[str(cid)]['street'] = streets[0][0]
    get_number(cid)
Esempio n. 3
0
def insert_seller(cid):
    db = dbaccess.SQLka()
    db.insert('sellers', (('seller_type', shelf[str(cid)]['seller_type']),
                          ('name', shelf[str(cid)]['name']),
                          ('phone_number', shelf[str(cid)]['phone_number']),
                          ('rating', 0), ('rates', 0)))
    acc = db.select(fields=['seller_id'],
                    tables=[('Sellers', 'sellers')],
                    constraints=[('phone_number',
                                  dbaccess.eq(shelf[str(cid)]['phone_number']))
                                 ])
    db.close()
    shelf[str(cid)]['seller_id'] = acc[0][0]
Esempio n. 4
0
def results_handler(call):
    interface = dbaccess.SQLka()
    shelf[str(call.message.chat.id)]['results'] = \
        interface.select(fields=shelf[str(call.message.chat.id)]['fields'],
                         tables=shelf[str(call.message.chat.id)]['tables'],
                         constraints=
                         shelf[str(call.message.chat.id)]['constraints'])
    shelf[str(call.message.chat.id)]['results_num'] = \
        len(shelf[str(call.message.chat.id)]['results'])
    msg = bot.send_message(call.message.chat.id, """
    Результатов найдено: {}
    """.format(shelf[str(call.message.chat.id)]['results_num']))
    print_result(call.message)
Esempio n. 5
0
def init_seller(message):
    shelf[str(message.chat.id)] = {}
    db = dbaccess.SQLka()
    cid = message.chat.id
    acc = db.select(fields=['seller_id'],
                    tables=[('Sellers', 'sellers')],
                    constraints=[('phone_number',
                                  dbaccess.eq("'{}'".format(
                                      message.contact.phone_number)))])
    db.close()
    if len(acc) == 0:
        shelf[str(cid)]['phone_number'] = dbaccess.id_str(
            message.contact.phone_number)
        get_name(message)
        return
    shelf[str(cid)]['seller_id'] = acc[0][0]
    get_building(cid)
Esempio n. 6
0
def insert_selling(cid):
    db = dbaccess.SQLka()
    fields = [('premise_id', shelf[str(cid)]['premise_id']),
              ('seller_id', shelf[str(cid)]['seller_id']),
              ('cost', shelf[str(cid)]['cost'])]
    db.insert('sellings', fields)
    db.close()

    class Msg:
        class Cht:
            def __init__(self, id):
                self.id = id

        def __init__(self, id):
            self.chat = self.Cht(id)

    message = Msg(cid)
    term_session(message)
Esempio n. 7
0
def get_number2(message):
    if message.text == '/end':
        return
    l = message.text.split()
    cid = message.chat.id
    try:
        shelf[str(cid)]['number'] = int(l[0])
    except ValueError:
        msg = bot.send_message(cid, text='Отправьте одно или два числа')
        bot.register_next_step_handler(msg, get_number2)
        return
    constraints = [('street',
                    dbaccess.eq(dbaccess.id_str(shelf[str(cid)]['street']))),
                   ('number', dbaccess.eq(shelf[str(cid)]['number']))]
    if len(l) > 1:
        try:
            shelf[str(cid)]['bld'] = int(l[1])
        except ValueError:
            msg = bot.send_message(cid, text='Отправьте одно или два числа')
            bot.register_next_step_handler(msg, get_number2)
            return
        constraints.append(('bld', dbaccess.eq(shelf[str(cid)]['bld'])))
    db = dbaccess.SQLka()

    b = db.select(fields=['building_id'],
                  tables=[('Buildings', 'buildings')],
                  constraints=constraints)
    db.close()
    if len(b) == 0:
        bot.send_message(cid,
                         text="""
        К сожалению, адрес не найден. Попробуй ещё раз! 
        """)
        get_building(cid)
        return

    shelf[str(cid)]['building_id'] = b[0][0]
    get_premise(cid)