-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_post.py
34 lines (27 loc) · 971 Bytes
/
bot_post.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
import requests
import configparser
import io
import sys
# Считываем учетные данные
config = configparser.ConfigParser()
config.read("config.ini")
# Присваиваем значения внутренним переменным
bot_token = config['Telegram']['bot_token']
bot_api_url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
bot_name = "бот"
#bot = telebot.TeleBot(bot_token)
#Входящий поток в переменную
sys.stdin.reconfigure(encoding='utf-8')
message = ""
for line in sys.stdin:
message += line
chat_id = sys.argv[1]
def post():
try:
#response = requests.post(bot_api_url, json={'chat_id': chat_id, 'text': message, 'disable_content_type_detection': None})
response = requests.post(bot_api_url, json={'chat_id': chat_id, 'text': message, 'parse_mode': 'html'})
print(response.text)
except Exception as e:
print(e)
if __name__=="__main__":
post()