-
Notifications
You must be signed in to change notification settings - Fork 49
/
create_messages.py
46 lines (33 loc) · 1.42 KB
/
create_messages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
import random
# This function allow us to create an HTML message to send
# You can edit all fields of message using HTML syntax
def create_item_html(items):
response = []
print(f'{5 * "*"} Creating post {5 * "*"}')
# Shuffling items
random.shuffle(items)
# Iterate over items
for item in items:
# If item has an active offer
if 'off' in item:
# Creating buy button
keyboard = [
[InlineKeyboardButton("🛒 Acquista ora 🛒", callback_data='buy', url=item["url"])],
]
reply_markup = InlineKeyboardMarkup(keyboard)
# Creating message body
html = ""
html += f"🎁 <b>{item['title']}</b> 🎁\n\n"
if 'description' in list(item.keys()):
html += f"{item['description']}\n"
html += f"<a href='{item['image']}'>‍</a>\n"
if 'savings' in list(item.keys()):
html += f"❌ Non più: {item['original_price']}€ ❌\n\n"
html += f"💰 <b>Al prezzo di: {item['price']}</b> 💰\n\n"
if 'savings' in list(item.keys()):
html += f"✅ <b>Risparmi: {item['savings']}€</b> ✅\n\n"
html += f"<b><a href='{item['url']}'></a></b>"
response.append(html)
response.append(reply_markup)
return response