-
Notifications
You must be signed in to change notification settings - Fork 15
/
message.py
23 lines (20 loc) · 822 Bytes
/
message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
import os
import sys
import configparser
telegram_info = configparser.RawConfigParser()
telegram_info.read('config.ini')
try:
telegram_bot_token = telegram_info['telegram']['bottoken']
telegram_chatid = telegram_info['telegram']['chatid']
except KeyError:
os.system("cls" if os.name == "nt" else "clear")
print("Run setup.py first")
sys.exit(1)
def telegram_send_message(message):
apiURL = f'https://api.telegram.org/bot{telegram_bot_token}/sendMessage'
try:
response = requests.post(apiURL, json={'chat_id': telegram_chatid, 'text': message, 'parse_mode': 'html', 'disable_web_page_preview': True})
print(response.text)
except Exception as e:
print(e)