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)
def cottage_handler(call): premise_type = 'cottage' shelf[str(call.message.chat.id)]['constraints'].append( ('premise_type', dbaccess.eq("'{}'".format(premise_type)))) if shelf[str(call.message.chat.id)]['state'] == 'buy': buy_filter(call.message.chat.id) elif shelf[str(call.message.chat.id)]['state'] == 'get_rent': get_rent_filter(call.message.chat.id)
def add_district(message): if message.text == '/end': return cond = 'district_name ' + dbaccess.eq("'{}'".format(message.text)) shelf[str(message.chat.id)]['tables'][3][1] = """ (SELECT * FROM districts WHERE {}) """.format(cond) if shelf[str(message.chat.id)]['state'] == 'buy': buy_filter(message.chat.id) elif shelf[str(message.chat.id)]['state'] == 'get_rent': get_rent_filter(message.chat.id)
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]
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)
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)