Skip to content

Commit

Permalink
Fix not sending issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom committed Nov 14, 2023
1 parent 9093cfd commit 26c8462
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ def get_speiseplan_tomorrow():
response = requests.get("https://mensa.mafiasi.de/api/canteens/10/tomorrow/")
return response.json()

def check_for_good_stuff(BOT_TOKEN, CHAT_ID):
def check_for_good_stuff(token, chat_id):
response = get_speiseplan_today()
vegan = ""
vegetarian = ""
fav = ""
if response:
Header = "Der **heutige** Speiseplan " + datetime.today().strftime("%d.%m.%Y") + " ist: \n"
send_message(Header, BOT_TOKEN, CHAT_ID)
send_message(token, chat_id, Header)
for meal in response:
if [ele for ele in good_stuff if (ele in meal['dish'])]:
fav = "⭐ "
Expand All @@ -34,46 +34,49 @@ def check_for_good_stuff(BOT_TOKEN, CHAT_ID):
vegan = ""
vegetarian = ""
fav = ""
send_message(meal_text, BOT_TOKEN, CHAT_ID)
send_message(token, chat_id, meal_text)


def send_poll(BOT_TOKEN, CHAT_ID):
def send_poll(token, chat_id):
"""
Send a poll to a specified Telegram chat.
Args:
token (str): Telegram Bot API token.
CHAT_ID (str): Chat ID where the poll is to be sent.
chat_id (str): Chat ID where the poll is to be sent.
question (str): The question of the poll.
options (list): A list of options for the poll.
Returns:
response: The response from the Telegram API.
"""
url = 'https://api.telegram.org/bot' + BOT_TOKEN + '/sendPoll'
chat_id = chat_id
url = 'https://api.telegram.org/bot' + token + '/sendPoll'
payload = {
'CHAT_ID': CHAT_ID,
'chat_id': chat_id,
'question': "Wann gehen wir heute essen?",
'options': json.dumps(["11:45", "12:00", "12:30", "13:00", "13:30"]),
'type': 'regular', # Change this to 'quiz' if you want to send a quiz instead of a poll
'allows_multiple_answers': True, # Change this to True if you want to allow multiple answers
'is_anonymous': False # Change this to True if you want the poll to be anonymous
}
response = requests.get(url, data=payload)
print(response.json())
return response.json()


def send_message(bot_message, BOT_TOKEN, CHAT_ID):
if "&" in bot_message:
bot_message = bot_message.replace("&", "und")
send_text = 'https://api.telegram.org/bot' + BOT_TOKEN + '/sendMessage?CHAT_ID=' + CHAT_ID + '&parse_mode=Markdown&text=' + bot_message
response = requests.get(send_text)
def send_message(token, chat_id, message):
parse_mode = 'Markdown'
url = f'https://api.telegram.org/bot{token}/sendMessage'
payload = {
'chat_id': chat_id,
'text': message,
'parse_mode': parse_mode
}
response = requests.post(url, json=payload)
return response.json()

def main():
print("starting Bot")
try:
check_for_good_stuff(sys.argv[1],sys.argv[2])
# check_for_good_stuff(token, CHAT_ID)
send_poll(sys.argv[1],sys.argv[2])
except UnboundLocalError:
print("Error: Please provide a valid token and chat id")
Expand Down

0 comments on commit 26c8462

Please sign in to comment.