import datetime
import io
from PIL import Image
from ppadb.client import Client as AdbClient

client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("192.168.178.32:5555")

def save_screenshot():
  result = device.screencap()

  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
  image = Image.open(io.BytesIO(result))
  jpeg_filename = f"/mnt/t/nextcloud/InstantUpload/Herowars/{timestamp}.jpg"

  image = image.convert('RGB')  # Convert to RGB mode for JPEG
  with open(jpeg_filename, "wb") as fp:
    image.save(fp, format='JPEG', quality=85)  # Adjust quality as needed

save_screenshot()
