import os
import requests
import smtplib
import ssl
import tempfile
import time
import urllib.request
import json
from datetime import datetime, timedelta
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_to_telegram(bot_token, chat_id, caption, *image_paths):
url = f"https://api.telegram.org/bot{bot_token}/sendMediaGroup"
media_group = []
for i, image_path in enumerate(image_paths):
with open(image_path, 'rb') as image_file:
image_data = image_file.read()
files = {
'photo': ('image.jpg', image_data, 'image/jpeg'),
}
response = requests.post(f"https://api.telegram.org/bot{bot_token}/uploadPhoto", files=files)
file_id = response.json()['result']['photo'][0]['file_id']
media_group.append({
'type': 'photo',
'media': file_id,
'caption': caption if i == 0 else "",
'parse_mode': 'HTML',
})
data = {
'chat_id': chat_id,
'media': json.dumps(media_group),
}
response = requests.post(url, data=data)
if response.status_code != 200:
raise ValueError(f"Request to Telegram API returned an error: {response.status_code}, {response.text}")
def create_email(sender_email, recipient_emails, subject, boot_time_str, image_path1, image_path2):
msg = MIMEMultipart("related")
msg["From"] = sender_email
msg["To"] = ",".join(recipient_emails)
msg["Subject"] = subject
msg_alternative = MIMEMultipart("alternative")
msg.attach(msg_alternative)
msg_text = MIMEText("This is the alternative plain text message.")
msg_alternative.attach(msg_text)
html_text = f'
Letzter Start: {boot_time_str} Uhr
' msg_html = MIMEText(html_text, "html") msg_alternative.attach(msg_html) with open(image_path1, "rb") as file: msg_image1 = MIMEImage(file.read()) msg_image1.add_header("Content-ID", "