59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
|
import os
|
||
|
from dotenv import load_dotenv
|
||
|
import logging
|
||
|
from typing import Any, Dict, Tuple
|
||
|
from requests import Session
|
||
|
import requests
|
||
|
|
||
|
|
||
|
load_dotenv()
|
||
|
|
||
|
LOGIN = os.getenv("ELJUR_LOGIN")
|
||
|
PASSWORD = os.getenv("ELJUR_PASSWORD")
|
||
|
DOMAIN = os.getenv("ELJUR_DOMAIN")
|
||
|
|
||
|
TG_TOKEN = os.getenv("TG_TOKEN")
|
||
|
TG_ID = os.getenv("TG_ID")
|
||
|
TG_API_URL = os.getenv("TG_API_URL")
|
||
|
|
||
|
|
||
|
logging.basicConfig(level=logging.DEBUG, filename="logfile.log",filemode="w")
|
||
|
|
||
|
if LOGIN == None or PASSWORD == None or DOMAIN == None or TG_TOKEN == None or TG_ID == None or TG_API_URL == None:
|
||
|
logging.critical("Env load error!")
|
||
|
exit(1)
|
||
|
|
||
|
TG_ID = int(TG_ID)
|
||
|
|
||
|
|
||
|
def send_photo(path):
|
||
|
url = f'{TG_API_URL}bot{TG_TOKEN}/sendPhoto'
|
||
|
|
||
|
params = {
|
||
|
'chat_id': TG_ID,
|
||
|
}
|
||
|
|
||
|
with open(path, 'rb') as img_file:
|
||
|
response = requests.post(url, params=params, files={'photo': img_file})
|
||
|
|
||
|
if response.status_code == 200:
|
||
|
logging.debug('photo sent')
|
||
|
else:
|
||
|
logging.error(f'can`t send photo: {response.status_code}')
|
||
|
|
||
|
|
||
|
def send_document(path):
|
||
|
url = f'{TG_API_URL}bot{TG_TOKEN}/sendDocument'
|
||
|
|
||
|
params = {
|
||
|
'chat_id': TG_ID,
|
||
|
}
|
||
|
|
||
|
with open(path, 'rb') as doc_file:
|
||
|
response = requests.post(url, params=params, files={'document': doc_file})
|
||
|
|
||
|
if response.status_code == 200:
|
||
|
logging.debug('doc sent')
|
||
|
else:
|
||
|
logging.error(f'can`t send document: {response.status_code}')
|