From 09536a76b573841675c76d0fc36901eed45582b8 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 21 Feb 2023 21:36:12 -0800 Subject: handle telegram built venue location --- bot.py | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index f9a664a..05483ca 100644 --- a/bot.py +++ b/bot.py @@ -6,6 +6,7 @@ import logging import io import telegram.constants from telegram import __version__ as TG_VER +from pprint import pprint try: from telegram import __version_info__ @@ -75,15 +76,48 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: - context.user_data["latitude"] = update.message.location.latitude - context.user_data["longitude"] = update.message.location.longitude + pprint(update.message.location) + if update.message.venue is not None: + fsq_id = update.message.venue.foursquare_id + title = update.message.venue.title + context.user_data["fsq_id"] = fsq_id + context.user_data["title"] = title + context.user_data["latitude"] = update.message.venue.location.latitude + context.user_data["longitude"] = update.message.venue.location.longitude + + poi = get_loc(context.user_data["fsq_id"]) + media_id = [] + content = f"I'm at {poi['name']} in {poi['locality']}, {poi['region']}, {poi['osm_url']}" + status = mastodon_client.status_post( + content, + visibility="private", + media_ids=media_id) + + context.user_data["status_id"] = status["id"] + context.user_data["status_content"] = content + + print("status_id", context.user_data["status_id"]) + + await update.message.reply_text( + text=f"Selected place: {poi['name']}, \nPosted to Mastodon: {status['url']}", + parse_mode=telegram.constants.ParseMode.MARKDOWN, + ) + + prompt_attach_photo_msg = await update.message.reply_text( + "You can continue attaching photos, or press skip to finish", reply_markup=SKIP_MENU) + context.user_data["prompt_attach_photo_msg_id"] = prompt_attach_photo_msg.message_id + + return PHOTO + else: + context.user_data["latitude"] = update.message.location.latitude + context.user_data["longitude"] = update.message.location.longitude - await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove()) - prompt_msg = await update.message.reply_text("You can input location search keywords or press skip", - reply_markup=SKIP_MENU) + await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove()) + prompt_msg = await update.message.reply_text("You can input location search keywords or press skip", + reply_markup=SKIP_MENU) - context.user_data["prompt_msg_id"] = prompt_msg.message_id - return LOCATION_SEARCH + context.user_data["prompt_msg_id"] = prompt_msg.message_id + return LOCATION_SEARCH async def process_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: -- cgit v1.2.3