def computeDistrict(call): global districtCode, districtIdentifier if call.data == 'district1': districtIdentifier = '''Core Central Districts - inclusive of:\n\n D1 - Temasek Blvd, Raffles Link\n D2 - Anson, Tanjong Pagar\n D4 - Telok Blangah, Harbourfront\n D6 - High Street, Beach Road\n D7 - Middle Road, Golden Mile\n D9 - Orchard, Cairnhill, River Valley\n D10 - Bukit Timah, Holland Rd, Tanglin\n D11 - Watten Estate, Novena, Thomson\n ''' districtCode = citi.districtFilter(1) r.hmset(call.message.chat.id,{"lastupdated":d.today(),"area":"Core Central Districts"}) #Save the area code if call.data == 'district2': districtIdentifier = '''Rest of Central Region - inclusive of:\n\n D2 - Anson, Tanjong Pagar\n D3 - Queenstown, Tiong Bahru\n D7 - Middle Road, Golden Mile\n D8 - Little India\n D12 - Balestier, Toa Payoh, Serangoon\n D13 - Macpherson, Braddell\n D14 - Geylang, Eunos\n D15 - Katong, Joo Chiat, Amber Road\n\n ''' districtCode = citi.districtFilter(2) r.hmset(call.message.chat.id,{"lastupdated":d.today(),"area":"Rest of Central Region"}) #Save the area code if call.data == 'district3': districtIdentifier = '''Outside Central Region - inclusive of:\n\n D5 - Pasir Panjang, Clementi\n D16 - Bedok, Upper East Coast\n D17 - Loyang, Changi\n D18 - Tampines, Pasir Ris\n D19 - Serangoon, Hougang, Punggol\n D20 - Bishan, Ang Mo Kio\n D21 - Upper Bukit Timah, Ulu Pandan\n D22 - Jurong\n D23 - Bukit Panjang, Choa Chu Kang\n D24 - Lim Chu Kang, Tengah\n D25 - Kranji, Woodgrove\n D26 - Upper Thomson, Springleaf\n D27 - Yishun, Sembawang\n D28 - Seletar ''' districtCode = citi.districtFilter(3) r.hmset(call.message.chat.id,{"lastupdated":d.today(),"area":"Outside Central Region"}) #Save the area code
def send_introduction(message): r.hmset(message.chat.id, {"lastupdated":d.today()}) print(message.chat.id) #Your user id = 276269485 print('\n\n\n\n\n') print(r.hgetall(message.chat.id)) print('\n\n\n\n\n') bot.send_message(message.chat.id, """Hi! I am your friendly Housing Bot, able to help you analyse your financial situation and eligibility for\ properties. Also, I can help you search for properties based on your budget and requirements! \n\n Sounds exciting? Enter any of the\ following commands to try out!\n'/ask': To analyse your financial situation and eligibility for properties\n\n\ '/mypref': To set up your preferences BEFORE the property search\n\n\ '/searchnow': To search for properties based on your budget and requirements\n\n\ '/info': To assess your saved profile and preferences""")
def whatcom2(message): chat_id = message.chat.id bot.send_chat_action(chat_id, 'typing') if message.text.isdigit(): global income2 income2 = int(message.text) r.hmset(message.chat.id,{"lastupdated":d.today(),"income2":income2}) #Monthly income of the second person msg = bot.send_message(chat_id, "What is your partner's monthly financial commitments and living expenses? \ (Eg. Car loans, credit card loans, personal loans.) Please enter a whole number") bot.register_next_step_handler(msg, assess_afford2) else: msg = bot.send_message(chat_id, "I am sorry, I didn't quite catch that... Please try again") bot.register_next_step_handler(msg, whatcom2)
def whatsalary2(message): chat_id = message.chat.id bot.send_chat_action(chat_id, 'typing') if message.text.isdigit(): global funds2 funds2 = int(message.text) r.hmset(message.chat.id,{"lastupdated":d.today(),"savings2":funds2}) # Money saved for House of the second person msg = bot.send_message(chat_id, "What is your partner's gross monthly income? Please enter a whole number") bot.register_next_step_handler(msg, whatcom2) else: msg = bot.send_message(chat_id, "I am sorry, I didn't quite catch that... Please try again") bot.register_next_step_handler(msg, whatsalary2)
def assess_afford2(message): chat_id = message.chat.id bot.send_chat_action(chat_id, 'typing') if message.text.isdigit(): global com2 global affordability com2 = int(message.text) r.hmset(message.chat.id,{"lastupdated":d.today(),"f_commitment2":com2}) #Saving the financial commitment of the second person affordability = assessing_afford(chat_id) bot.send_message(chat_id, "Your maximum affordability calculated is ${}.\ For a better reflection of your affordability, do consult a bank regarding loans available for you :)".format(affordability)) bot.send_message(chat_id, "If you would like me to do other things for you, just enter '/start'! :)") else: msg = bot.send_message(chat_id, "I am sorry, I didn't quite catch that... Please try again") bot.register_next_step_handler(msg, assess_afford2)
def logTextMessage(message): # split if they type 500000,600000 if len(message.text.split(','))==2: #'1','2' global minimum, maximum, budget minimum = int(message.text.split(',')[0]) #'1,2' -> [1,2] maximum = int(message.text.split(',')[1]) budget = (citi.budget(minimum,maximum)) #budget logged print('\n\n\n') r.hmset(message.chat.id,{"lastupdated":d.today(),"budget":[minimum,maximum]}) print(r.hgetall(message.chat.id)) redisData = r.hget(message.chat.id,"budget") print(redisData.decode('utf-8')) print('\n\n\n') print('Your budget = (minimum,maximum) = {},{}'.format(minimum,maximum)) bot.send_message(message.chat.id, 'Enter /sort to indicate your search preference')
def assess_afford(message): chat_id = message.chat.id bot.send_chat_action(chat_id, 'typing') if message.text.isdigit(): global com1 global affordability com1 = int(message.text) r.hmset(message.chat.id,{"lastupdated":d.today(),"f_commitment1":com1}) #Saving the financial commitment of the 1st person if joint2 == "On my own": affordability = assessing_afford(chat_id) bot.send_message(chat_id, "Your maximum affordability calculated is ${}.\ For a better reflection of your affordability, do consult a bank regarding loans available for you :)".format(affordability)) bot.send_message(chat_id, "If you would like me to do other things for you, just enter '/start'! :)") else: msg = bot.send_message(chat_id, "How much funds does your partner have available? (Include CPF OA savings & Personal Savings)\ \n\nPlease enter a whole number") bot.register_next_step_handler(msg, whatsalary2) else: msg = bot.send_message(chat_id, "I am sorry, I didn't quite catch that... Please try again") bot.register_next_step_handler(msg, assess_afford)
def searchProperty(message): print(citi.addPropertyTypeFilter(propertyTypeSelection)) new_url = citi.urlGenerator(citi.addPropertyTypeFilter(propertyTypeIdentifier), budget) print(new_url) bot.send_message(message.chat.id, 'Searching in progress\nPlease wait patiently') longdict = citi.getAllListingDetails(citi.getListingLinks(new_url)) global messageStorage messageStorage = [] for index, listing in enumerate(longdict): messageStorage.append(str(longdict[listing]).strip("{}").replace(":'","").replace("'", '')) r.hmset(message.chat.id, {"lastupdated":d.today(),"propertylistingsData":messageStorage}) keyboard = types.InlineKeyboardMarkup() nextButton = types.InlineKeyboardButton(text='Next', callback_data='next') favButton = types.InlineKeyboardButton(text='Favorite', callback_data='fav') keyboard.row(nextButton) keyboard.row(favButton) bot.send_message(message.chat.id, messageStorage[0], reply_markup=keyboard) bot.send_message(message.chat.id, "If you would like me to do other things for you, just enter '/start'! :)")
def callback_inline(call): global counter, sort selections = ['hdb-1', 'hdb-2','hdb-3','hdb-4','hdb-5', 'condo', 'landed'] if call.message: # Processes only buttons from messages if call.data == 'hdb': print('User has picked HDB') pickHDBroom(call) elif call.data in selections: print('Picking District') print('User has picked a {}-room flat'.format(getDistrict(call))) global propertyTypeSelection, propertyTypeIdentifier if call.data == 'hdb-1': propertyTypeSelection = 'HDB: 1 Room Flat' propertyTypeIdentifier = 'hdb-1' r.hmset(call.message.chat.id,{"lastupdated":d.today(),"property_Type":propertyTypeSelection}) #Save the property type if call.data == 'hdb-2': propertyTypeSelection = 'HDB: 2 Room Flat' propertyTypeIdentifier = 'hdb-2' r.hmset(call.message.chat.id,{"lastupdated":d.today(),"property_Type":propertyTypeSelection}) #Save the property type if call.data == 'hdb-3': propertyTypeSelection = 'HDB: 3 Room Flat' propertyTypeIdentifier = 'hdb-3' r.hmset(call.message.chat.id,{"lastupdated":d.today(),"property_Type":propertyTypeSelection}) #Save the property type if call.data == 'hdb-4': propertyTypeSelection = 'HDB: 4 Room Flat' propertyTypeIdentifier = 'hdb-4' r.hmset(call.message.chat.id,{"lastupdated":d.today(),"property_Type":propertyTypeSelection}) #Save the property type if call.data == 'hdb-5': propertyTypeSelection = 'HDB: 5 Room Flat' propertyTypeIdentifier = 'hdb-5' r.hmset(call.message.chat.id,{"lastupdated":d.today(),"property_Type":propertyTypeSelection}) #Save the property type if call.data == 'condo': propertyTypeSelection = 'Condominium' propertyTypeIdentifier = 'condo' r.hmset(call.message.chat.id,{"lastupdated":d.today(),"property_Type":propertyTypeSelection}) #Save the property type if call.data == 'landed': propertyTypeSelection = 'Landed Property' propertyTypeIdentifier = 'landed' r.hmset(call.message.chat.id,{"lastupdated":d.today(),"property_Type":propertyTypeSelection}) #Save the property type getDistrict(call) elif call.data == 'district1' or call.data == 'district2' or call.data == 'district3': computeDistrict(call) askBudget(call) elif call.data == 'next': counter += 1 nextItemListing(call) elif call.data == 'previous': counter -= 1 nextItemListing(call) elif call.data == 'fav': print(call) if len(favouriteList)<=1: favouriteList.append(call.message.text) else: bot.send_message(call.message.chat.id, 'You have a reached a maximum of 2 favourites. Enter /info to view and clear your favourited apartments.') print(favouriteList) elif call.data == 'addr' or call.data == 'price' or call.data == 'size' or call.data == 'psf': sort = call.data finalisedPreference(call)