diff options
author | clarkzjw <[email protected]> | 2023-02-21 21:36:12 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-21 21:36:12 -0800 |
commit | 09536a76b573841675c76d0fc36901eed45582b8 (patch) | |
tree | c45bdde0dd395ace8477b57672dac9a5bd457693 | |
parent | 360eeec8df66ca0402739463ac0fdf9b5d5910f3 (diff) | |
download | swarm2fediverse-09536a76b573841675c76d0fc36901eed45582b8.tar.gz |
handle telegram built venue location
-rw-r--r-- | bot.py | 48 |
1 files changed, 41 insertions, 7 deletions
@@ -6,6 +6,7 @@ import logging | |||
6 | import io | 6 | import io |
7 | import telegram.constants | 7 | import telegram.constants |
8 | from telegram import __version__ as TG_VER | 8 | from telegram import __version__ as TG_VER |
9 | from pprint import pprint | ||
9 | 10 | ||
10 | try: | 11 | try: |
11 | from telegram import __version_info__ | 12 | from telegram import __version_info__ |
@@ -75,15 +76,48 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | |||
75 | 76 | ||
76 | 77 | ||
77 | async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 78 | async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
78 | context.user_data["latitude"] = update.message.location.latitude | 79 | pprint(update.message.location) |
79 | context.user_data["longitude"] = update.message.location.longitude | 80 | if update.message.venue is not None: |
81 | fsq_id = update.message.venue.foursquare_id | ||
82 | title = update.message.venue.title | ||
83 | context.user_data["fsq_id"] = fsq_id | ||
84 | context.user_data["title"] = title | ||
85 | context.user_data["latitude"] = update.message.venue.location.latitude | ||
86 | context.user_data["longitude"] = update.message.venue.location.longitude | ||
87 | |||
88 | poi = get_loc(context.user_data["fsq_id"]) | ||
89 | media_id = [] | ||
90 | content = f"I'm at {poi['name']} in {poi['locality']}, {poi['region']}, {poi['osm_url']}" | ||
91 | status = mastodon_client.status_post( | ||
92 | content, | ||
93 | visibility="private", | ||
94 | media_ids=media_id) | ||
95 | |||
96 | context.user_data["status_id"] = status["id"] | ||
97 | context.user_data["status_content"] = content | ||
98 | |||
99 | print("status_id", context.user_data["status_id"]) | ||
100 | |||
101 | await update.message.reply_text( | ||
102 | text=f"Selected place: {poi['name']}, \nPosted to Mastodon: {status['url']}", | ||
103 | parse_mode=telegram.constants.ParseMode.MARKDOWN, | ||
104 | ) | ||
105 | |||
106 | prompt_attach_photo_msg = await update.message.reply_text( | ||
107 | "You can continue attaching photos, or press skip to finish", reply_markup=SKIP_MENU) | ||
108 | context.user_data["prompt_attach_photo_msg_id"] = prompt_attach_photo_msg.message_id | ||
109 | |||
110 | return PHOTO | ||
111 | else: | ||
112 | context.user_data["latitude"] = update.message.location.latitude | ||
113 | context.user_data["longitude"] = update.message.location.longitude | ||
80 | 114 | ||
81 | await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove()) | 115 | await update.message.reply_text("Searching...", reply_markup=telegram.ReplyKeyboardRemove()) |
82 | prompt_msg = await update.message.reply_text("You can input location search keywords or press skip", | 116 | prompt_msg = await update.message.reply_text("You can input location search keywords or press skip", |
83 | reply_markup=SKIP_MENU) | 117 | reply_markup=SKIP_MENU) |
84 | 118 | ||
85 | context.user_data["prompt_msg_id"] = prompt_msg.message_id | 119 | context.user_data["prompt_msg_id"] = prompt_msg.message_id |
86 | return LOCATION_SEARCH | 120 | return LOCATION_SEARCH |
87 | 121 | ||
88 | 122 | ||
89 | async def process_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 123 | async def process_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |