diff options
Diffstat (limited to 'bot.py')
-rw-r--r-- | bot.py | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -26,9 +26,10 @@ from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update | |||
26 | from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters | 26 | from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters |
27 | 27 | ||
28 | from config import BOT_TOKEN | 28 | from config import BOT_TOKEN |
29 | from foursquare.query_poi import query_poi | 29 | from foursquare.poi import query_poi, get_poi_top_photo |
30 | from dbstore.dbm_store import get_loc | 30 | from dbstore.dbm_store import get_loc |
31 | from toot import mastodon_client | 31 | from toot import mastodon_client |
32 | import urllib.request | ||
32 | 33 | ||
33 | # Enable logging | 34 | # Enable logging |
34 | logging.basicConfig( | 35 | logging.basicConfig( |
@@ -66,12 +67,20 @@ async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | |||
66 | 67 | ||
67 | await query.answer() | 68 | await query.answer() |
68 | poi = get_loc(query.data) | 69 | poi = get_loc(query.data) |
70 | photo_url = get_poi_top_photo(query.data) | ||
71 | media_id = None | ||
72 | if photo_url is not None: | ||
73 | with urllib.request.urlopen(photo_url) as response: | ||
74 | data = response.read() | ||
75 | media = mastodon_client.media_post(data, mime_type="image/jpeg") | ||
76 | media_id = [media["id"]] | ||
69 | 77 | ||
70 | status = mastodon_client.status_post( | 78 | status = mastodon_client.status_post( |
71 | f"I'm at {poi['name']} in {poi['locality']}, {poi['region']}, {poi['osm_url']}", | 79 | f"I'm at {poi['name']} in {poi['locality']}, {poi['region']}, {poi['osm_url']}", |
72 | visibility="private") | 80 | visibility="private", |
81 | media_ids=media_id) | ||
73 | 82 | ||
74 | await query.edit_message_text(text=f"Selected place: {poi['name']}\nPosted to Mastodon: {status['url']}", | 83 | await query.edit_message_text(text=f"Selected place: {poi['name']}, `{query.data}`\nPosted to Mastodon: {status['url']}", |
75 | parse_mode=telegram.constants.ParseMode.MARKDOWN) | 84 | parse_mode=telegram.constants.ParseMode.MARKDOWN) |
76 | 85 | ||
77 | 86 | ||