def location(bot, update): urld = 'http://api.citysdk.waag.org/layers/parking.garage/objects?per_page=25' user = User.objects.get(chat_id=update.message.chat_id) User.objects.filter(chat_id=update.message.chat_id).update( lastCommand="parking") cronologyHandler.createCronology(bot, update, user) r = urllib.request.urlopen(urld) data = json.loads(r.read().decode(r.info().get_param('charset') or 'utf-8')) closestParkings, closestDistance = calculate_parkings_distance( bot, update, data['features']) print(closestDistance) url, keyboard = utility.getDecoratedMap(bot, update, closestParkings, data['features'], closestDistance) reply_markup = InlineKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) #bot.sendPhoto(chat_id = update.message.chat_id, photo=url) bot.sendMessage(chat_id=update.message.chat_id, text="Choose for more details: ", reply_markup=reply_markup) reply_markup = telegram.ReplyKeyboardRemove() #bot.sendMessage(chat_id = update.message.chat_id, text="Type /parking to start another search.", reply_markup=reply_markup) #sendMessageForParkings(closestParkings, data['features'], bot, update) userHandler.setUserBotActived(update.message.chat_id, True)
def sendMessageForSingleChargePoint(bot, update, index): urld = 'https://kaart.amsterdam.nl/datasets/datasets-item/t/parkeerlocaties-1/export/json' r = urllib.request.urlopen(urld) data = json.loads(r.read().decode(r.info().get_param('charset') or 'utf-8')) reverse_geocode_result = main.gmaps.reverse_geocode((data['features'][int(index)]['geometry']['coordinates'][1], data['features'][int(index)]['geometry']['coordinates'][0])) addressName = reverse_geocode_result[0]['address_components'][1]['short_name'] + " " + reverse_geocode_result[0]['address_components'][0]['short_name'] parkingCost = checkElectricChargeCost(addressName) message = "<b>The charge point is: </b>" + data['features'][int(index)]['properties']['title'] + "\n" electricChargeCost = checkElectricChargeCost(addressName) message += "<b>The address of the charge point is: </b>" + reverse_geocode_result[0]['formatted_address'] + "\n" if parkingCost is not "": message += "<b>Cost: </b>" + parkingCost bot.sendLocation(update.message.chat_id, data['features'][int(index)]['geometry']['coordinates'][1], data['features'][int(index)]['geometry']['coordinates'][0]) bot.sendMessage(chat_id=update.message.chat_id, text = message, parse_mode='HTML') latid = data['features'][int(index)]['geometry']['coordinates'][1] long = data['features'][int(index)]['geometry']['coordinates'][0] User.objects.filter(chat_id=update.message.chat_id).update(lat=latid, lon=long) User.objects.filter(chat_id=update.message.chat_id).update(lastCommand = "chargePoint.afterDetails") User.objects.filter(chat_id=update.message.chat_id).update(positionName = reverse_geocode_result[0]['formatted_address']) btn_keyboard1 = KeyboardButton(text="Find another electric charge point") btn_keyboard2 = KeyboardButton(text="Find closest parking") btn_keyboard3 = KeyboardButton(text="That's all, thanks") custom_keyboard = [[btn_keyboard1],[btn_keyboard2],[btn_keyboard3]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True, one_time_keyboard=True) userHandler.setUserBotActived(update.message.chat_id, True) bot.sendMessage(chat_id = update.message.chat_id, text="What do you want to do now ?", reply_markup=reply_markup)
def sendMessageForSingleParking(bot, update, index): urld = 'http://api.citysdk.waag.org/layers/parking.garage/objects?per_page=25' r = urllib.request.urlopen(urld) data = json.loads(r.read().decode(r.info().get_param('charset') or 'utf-8')) reverse_geocode_result = main.gmaps.reverse_geocode( (data['features'][int(index)]['geometry']['coordinates'][1], data['features'][int(index)]['geometry']['coordinates'][0])) addressName = reverse_geocode_result[0]['address_components'][1][ 'short_name'] + " " + reverse_geocode_result[0]['address_components'][ 0]['short_name'] parkingCost = checkParkingCost(addressName) message = "<b>The parking is: </b>" + data['features'][int( index)]['properties']['title'] + "\n" try: message += "<b>Free short parkings: </b>" + str( data['features'][int(index)]['properties']['layers'] ['parking.garage']['data']['FreeSpaceShort']) + "\n" except KeyError: message += "<b>Free short parkings: </b>" + '---' + "\n" try: message += "<b>Free long parkings: </b>" + str( data['features'][int(index)]['properties']['layers'] ['parking.garage']['data']['FreeSpaceLong']) + "\n" except KeyError: message += "<b>Free long parkings: </b>" + '---' + "\n" message += "<b>The address of the parking is: </b>" + reverse_geocode_result[ 0]['formatted_address'] + "\n" if parkingCost is not "": message += "<b>Cost: </b>" + parkingCost bot.sendLocation( update.message.chat_id, data['features'][int(index)]['geometry']['coordinates'][1], data['features'][int(index)]['geometry']['coordinates'][0]) bot.sendMessage(chat_id=update.message.chat_id, text=message, parse_mode='HTML') latid = data['features'][int(index)]['geometry']['coordinates'][1] long = data['features'][int(index)]['geometry']['coordinates'][0] User.objects.filter(chat_id=update.message.chat_id).update(lat=latid, lon=long) User.objects.filter(chat_id=update.message.chat_id).update( lastCommand="parking.afterDetails") User.objects.filter(chat_id=update.message.chat_id).update( positionName=reverse_geocode_result[0]['formatted_address']) btn_keyboard1 = KeyboardButton(text="Find another parking") btn_keyboard2 = KeyboardButton(text="Find closest electric charge point") btn_keyboard3 = KeyboardButton(text="Show my profile") btn_keyboard4 = KeyboardButton(text="That's all, thanks") custom_keyboard = [[btn_keyboard1], [btn_keyboard2], [btn_keyboard3], [btn_keyboard4]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True, one_time_keyboard=True) userHandler.setUserBotActived(update.message.chat_id, True) bot.sendMessage(chat_id=update.message.chat_id, text="What do you want to do now ?", reply_markup=reply_markup)
def location(bot, update): # Colors: Red, Blue, Purple, Green, Yellow, Brown, Orange, Grey listOfColor = ['#8B0000', '#0000FF', '#8A2BE2', '#228B22', '#FFD700', '#8B4513', '#D2691E', '#808080' user = User.objects.get(chat_id=update.message.chat_id) point = Point(user.lon, user.lat) # Distance in KM to search the parkings close by radius = 0.5 radius = radius / 40000 * 360 circle = point.buffer(radius) shape = multiPolygonHandler.getMultiPolygonByPoint(point) m = StaticMap(600, 800, 12, 12, tile_size=256) marker_outline = CircleMarker((user.lon, user.lat), 'white', 22) marker = CircleMarker((user.lon, user.lat), 'Red', 18) m.add_marker(marker_outline) m.add_marker(marker) circleLine = Line(circle[0], color='red', width=3) geoCircle = GEOPolygon(circle[0]) # Draw the circle for compare it with closest parkings m.add_line(circleLine) listPolygon, listOfColor2, listOfMultiPolygon = getAllPolygonsInCircleArea(geoCircle) i = 0 if len(listPolygon) is not 0: for p in listPolygon: polygonLine = Line(p[0], color=listOfColor[i], width=3) m.add_line(polygonLine) i = i + 1 image = m.render(zoom=14) fileName = 'ParkingStreet' + str(update.message.chat_id) + '.png' image.save(fileName) baseDir = settings.BASE_DIR picture = open(baseDir + '/' + fileName, 'rb') text = buildParkingZoneMessage(listOfMultiPolygon) btn_keyboard1 = KeyboardButton(text="Find another parking") btn_keyboard2 = KeyboardButton(text="Find closest electric charge point") btn_keyboard3 = KeyboardButton(text="Show my profile") btn_keyboard4 = KeyboardButton(text="That's all, thanks") custom_keyboard = [[btn_keyboard1], [btn_keyboard2], [btn_keyboard3], [btn_keyboard4]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True, one_time_keyboard=True) bot.sendPhoto(chat_id=update.message.chat_id, photo=picture) bot.sendMessage(chat_id=update.message.chat_id, text=text, parse_mode='HTML') bot.sendMessage(chat_id=update.message.chat_id, text='What do you want to do now?', reply_markup=reply_markup) userHandler.setUserBotActived(update.message.chat_id, True) else: btn_keyboard1 = KeyboardButton(text="Find another parking") btn_keyboard2 = KeyboardButton(text="Find closest electric charge point") btn_keyboard3 = KeyboardButton(text="Show my profile") btn_keyboard4 = KeyboardButton(text="That's all, thanks") custom_keyboard = [[btn_keyboard1], [btn_keyboard2], [btn_keyboard3], [btn_keyboard4]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True, one_time_keyboard=True) bot.sendMessage(chat_id=update.message.chat_id, text='There is no parking info close to your position.') bot.sendMessage(chat_id=update.message.chat_id, text='What do you want to do now?', reply_markup=reply_markup) userHandler.setUserBotActived(update.message.chat_id, True)
def location(bot, update): urld = 'https://kaart.amsterdam.nl/datasets/datasets-item/t/parkeerlocaties-1/export/json' user = User.objects.get(chat_id=update.message.chat_id) User.objects.filter(chat_id=update.message.chat_id).update(lastCommand="chargePoint") cronologyHandler.createCronology(bot, update, user) r = urllib.request.urlopen(urld) data = json.loads(r.read().decode(r.info().get_param('charset') or 'utf-8')) closestChargePoints, closestDistance = calculate_charge_point_distance(bot, update, data['features']); url, keyboard = utility.getDecoratedMap(bot, update, closestChargePoints, data['features'], closestDistance) reply_markup = InlineKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) bot.sendMessage(chat_id = update.message.chat_id, text="Choose for more details: ", reply_markup=reply_markup) reply_markup = telegram.ReplyKeyboardRemove() userHandler.setUserBotActived(update.message.chat_id, True)
def parking(bot, update): user = User.objects.get(chat_id=update.message.chat_id) User.objects.filter(chat_id=update.message.chat_id).update( lastCommand="parking") cronologyHandler.createCronology(bot, update, user) locationGPS_keyboard = KeyboardButton(text="Send my GPS location", request_location=True) locationUser_keyboard = KeyboardButton(text="Choose another location") custom_keyboard = [[locationGPS_keyboard], [locationUser_keyboard]] addPreferencesKeyboard(custom_keyboard, user) reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard, resize_keyboard=True, one_time_keyboard=True) userHandler.setUserBotActived(update.message.chat_id, False) bot.sendMessage( chat_id=update.message.chat_id, text= "Would you mind sharing your location to search the closest parking?", reply_markup=reply_markup)