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 get_name(message): cid = message.chat.id name = "{} {}".format(message.from_user.first_name, message.from_user.last_name) if re.match(config.name_re, name): shelf[str(cid)]['name'] = dbaccess.id_str(name) get_seller_type(cid) else: msg = bot.send_message(cid, "Введите ФИО:") bot.register_next_step_handler(msg, get_name2)
def get_name2(message): if message.text == '/end': return cid = message.chat.id name = ' '.join(message.text.split()) if re.match(config.name_re, name): shelf[str(cid)]['name'] = dbaccess.id_str(name) get_seller_type(cid) else: msg = bot.send_message(cid, "Некорректный ввод. Введите ФИО:") bot.register_next_step_handler(msg, get_name2)
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)
def insert_rent(cid): db = dbaccess.SQLka() fields = [('premise_id', shelf[str(cid)]['premise_id']), ('seller_id', shelf[str(cid)]['seller_id']), ('cost', shelf[str(cid)]['cost']), ('period', dbaccess.id_str(shelf[str(cid)]['period']))] db.insert('rents', 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)
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 type_ind(call): cid = call.message.chat.id shelf[str( call.message.chat.id)]['seller_type'] = dbaccess.id_str('company') insert_seller(cid) get_building(cid)