def weather(update, context): url = 'http://api.openweathermap.org/data/2.5/weather?q={' \ '}&units=metric&appid=37ad0e70f360a5a1a7f2c51a7c598d47' city = update.effective_message.text city = city.replace("/weather", "") # print(request.POST) try: r = requests.get(url.format(city)).json() # print(r) city_weather = { 'icon': r['weather'][0]['icon'], 'temperature': r['main']['temp'], 'description': r['weather'][0]['description'], 'feels_like': r['main']['feels_like'], 'humidity': r['main']['humidity'], } Icon = "http://openweathermap.org/img/w/{}.png".format( city_weather['icon']) chat_id = update.message.chat.id bot.send_photo(chat_id, Icon) weather_result = "Temperature:- " + str( city_weather['temperature']) + "°C" weather_result1 = "Description:- " + str(city_weather['description']) weather_result2 = "Feels Like:- " + str( city_weather['feels_like']) + "°C" weather_result3 = "Humidity:- " + str(city_weather['humidity']) + "%" update.message.reply_text(weather_result) update.message.reply_text(weather_result1) update.message.reply_text(weather_result2) update.message.reply_text(weather_result3) except KeyError: update.message.reply_text("No city found")
def sendImage(file_location): config = configparser.ConfigParser() config.read("cfg/settings.ini") bot_token = config["INTEGRATION"]['telegramToken'] bot_chatID = config["INTEGRATION"]['telegramChatID'] bot.send_photo(bot_chatID, 'https://random.dog/woof.json') return response.json()
def history_graph(bot, update, send_to_group: bool = False): x = [] y = [] with open(db_file, 'r') as db: for line in db.readlines( )[2:]: # skips first 2 lines which only contain a 0 # starting date x.append(str(line.split("- ")[1].split(" ")[0])) # number of asds y.append(int(line.split("\t")[0])) plt.plot(x, y) plt.xticks(x, rotation=90) plt.tick_params(axis='x', which='major', labelsize=8) plt.tight_layout() if os.path.exists("./history_graph.png"): Popen(["rm", "history_graph.png"]) plt.savefig("history_graph.png", dpi=300, bbox_inches='tight') if send_to_group: bot.send_photo(chat_id=weee_chat_chat_id, photo=open("history_graph.png", 'rb')) else: bot.send_photo(chat_id=update.message.chat_id, photo=open("history_graph.png", 'rb'))
def chart(bot, update): try: fig = create_chart() except: update.message.reply_text('Chart could not be created') filepath = '/home/pi/lndbot/charts/lnd_chart.png' fig.savefig(fname=filepath, dpi=300, bbox_inches='tight') bot.send_photo(chat_id=update.message.chat_id, photo=open(filepath, 'rb'))
def process_export(bot, update): query = update.callback_query bot.edit_message_text( text="{} {}".format(query.message.text, query.data), chat_id=query.message.chat_id, message_id=query.message.message_id) if query.data == 'png': quizes = quiz_storage.get_completed_quizes(query.message.chat_id) plot = get_quizes_plot(quizes) bot.send_photo(chat_id=query.message.chat_id, photo=plot) if query.data == 'csv': quizes = quiz_storage.get_completed_quizes(query.message.chat_id, limit=999) csv_buf = get_csv(quizes) bot.send_document(chat_id=query.message.chat_id, document=csv_buf, filename='m00d.csv')
def send_prediction_on_photo(bot: Bot, update): # Нам нужно получить две картинки, чтобы произвести перенос стиля, но каждая картинка приходит в # отдельном апдейте, поэтому в простейшем случае мы будем сохранять id первой картинки в память, # чтобы, когда уже придет вторая, мы могли загрузить в память уже сами картинки и обработать их. chat_id = update.message.chat_id if chat_id not in first_image_file: bot.send_message( chat_id, 'Крутяк! Исходная картинка есть, теперь отправляй картинку со стилем' ) # получаем информацию о картинке image_info = update.message.photo[-1] image_file = bot.get_file(image_info) if chat_id in first_image_file: # первая картинка, которая к нам пришла станет content image, а вторая style image content_image_stream = BytesIO() first_image_file[chat_id].download(out=content_image_stream) del first_image_file[chat_id] style_image_stream = BytesIO() image_file.download(out=style_image_stream) bot.send_message( chat_id, 'Стиль получен! Пошёл работать.\nМожешь выпить пока чайку, потому что я считаю на cpu(' ) output = model.transfer_style(model.open_image(content_image_stream), model.open_image(style_image_stream)) # теперь отправим назад фото output_stream = BytesIO() output.save(output_stream, format='PNG') output_stream.seek(0) bot.send_message(chat_id, 'TADAAAM!') bot.send_photo(chat_id, photo=output_stream) print("Sent Photo to user") else: first_image_file[chat_id] = image_file
def photo_handler(update: Update, context: CallbackContext): photo = update.message.photo[-1] photo_id = photo.file_id photo_meta = bot.get_file(photo_id) photo_meta.download('image.jpg') fen = photo_to_fen('./image.jpg') context.user_data["fen"] = fen fen_parts = [None] * 6 fen_parts[0] = fen[:-1] board = Board(fen_parts) boardGrid = board.board boardImg = DrawImage(boardGrid, 'png', './', 'result') boardImg.create() boardImg.to_image() stockfish_engine.set_fen_position(fen) chat_id = update.message.chat.id bot.send_photo(chat_id, photo=open('result.png', 'rb'), caption="Here is detected chessboard configuration")
def history_graph(bot, update, chat_id: str = ""): # the function has been invoked by a user, otherwise it has been invoked by notify() if chat_id == "": chat_id = str(update.message.chat_id) x = [] y = [] with open(counts_dir + chat_id + db_file, 'r') as db: for line in db.readlines( )[2:]: # skips first 2 lines which only contain a 0 # starting date x.append(str(line.split("- ")[1].split(" ")[0])) # number of asds y.append(int(line.split("\t")[0])) plt.plot(x, y) plt.xticks(x, rotation=90) plt.tick_params(axis='x', which='major', labelsize=8) plt.tight_layout() path_to_graph = counts_dir + chat_id + graph_file if os.path.exists(path_to_graph): Popen(["rm", path_to_graph]) plt.savefig(path_to_graph, dpi=300, bbox_inches='tight') bot.send_photo(chat_id=chat_id, photo=open(path_to_graph, 'rb'))
def answer(c): key = types.InlineKeyboardMarkup() cat_button = types.InlineKeyboardButton(text='Cat', callback_data='cat') dog_button = types.InlineKeyboardButton(text='Dog', callback_data='dog') panda_button = types.InlineKeyboardButton(text='Panda', callback_data='panda') red_panda_button = types.InlineKeyboardButton(text='Red Panda', callback_data='red_panda') koala_button = types.InlineKeyboardButton(text='Koala', callback_data='koala') fox_button = types.InlineKeyboardButton(text='Fox', callback_data='fox') key.add(cat_button, dog_button, panda_button, red_panda_button, fox_button, koala_button) if c.data == 'cat': bot.send_photo(c.message.chat.id, photo=get_url_cats()) bot.send_message(c.message.chat.id, 'Select your pet', reply_markup=key) elif c.data == 'dog': bot.send_photo(c.message.chat.id, photo=get_image_dog()) bot.send_message(c.message.chat.id, 'Select your pet', reply_markup=key) elif c.data == 'panda': bot.send_photo(c.message.chat.id, photo=get_url_panda()) bot.send_message(c.message.chat.id, 'Select your pet', reply_markup=key) elif c.data == 'red_panda': bot.send_photo(c.message.chat.id, photo=get_url_red_panda()) bot.send_message(c.message.chat.id, 'Select your pet', reply_markup=key) elif c.data == 'fox': bot.send_photo(c.message.chat.id, photo=get_url_fox()) bot.send_message(c.message.chat.id, 'Select your pet', reply_markup=key) elif c.data == 'koala': bot.send_photo(c.message.chat.id, photo=get_url_koala()) bot.send_message(c.message.chat.id, 'Select your pet', reply_markup=key)
def bop(bot, update): url = get_url() chat_id = update.message.chat_id print(chat_id) bot.send_photo(chat_id=chat_id, photo=url)