feat: add screenshot_scout.py
This commit is contained in:
parent
a3ee6f25e9
commit
f12d77a185
56
screenshot_scout.py
Normal file
56
screenshot_scout.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import asyncio
|
||||||
|
import httpx
|
||||||
|
from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError
|
||||||
|
|
||||||
|
SCREENSHOT_PATH = "/tmp/screenshot.png"
|
||||||
|
TELEGRAM_BOT_TOKEN = "8865512961:AAG4VVJk7S58oAF5Ps00xgwfoPjXobbcm1E"
|
||||||
|
TELEGRAM_CHAT_ID = "-1004385538803"
|
||||||
|
TELEGRAM_API_URL = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendPhoto"
|
||||||
|
TARGET_URL = "https://www.google.com"
|
||||||
|
|
||||||
|
|
||||||
|
async def capture_screenshot() -> bool:
|
||||||
|
try:
|
||||||
|
async with async_playwright() as p:
|
||||||
|
browser = await p.chromium.launch(headless=True)
|
||||||
|
page = await browser.new_page()
|
||||||
|
await page.goto(TARGET_URL, wait_until="networkidle", timeout=30000)
|
||||||
|
await page.screenshot(path=SCREENSHOT_PATH, full_page=True)
|
||||||
|
await browser.close()
|
||||||
|
print(f"[+] Screenshot saved to {SCREENSHOT_PATH}")
|
||||||
|
return True
|
||||||
|
except PlaywrightTimeoutError:
|
||||||
|
print(f"[-] Timeout loading {TARGET_URL}")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[-] Error: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def send_screenshot() -> bool:
|
||||||
|
try:
|
||||||
|
with open(SCREENSHOT_PATH, "rb") as photo:
|
||||||
|
with httpx.Client(timeout=30.0) as client:
|
||||||
|
resp = client.post(
|
||||||
|
TELEGRAM_API_URL,
|
||||||
|
data={"chat_id": TELEGRAM_CHAT_ID, "caption": f"Screenshot of {TARGET_URL}"},
|
||||||
|
files={"photo": ("screenshot.png", photo, "image/png")},
|
||||||
|
)
|
||||||
|
if resp.status_code == 200 and resp.json().get("ok"):
|
||||||
|
print("[+] Screenshot sent to Telegram!")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print(f"[-] Telegram error: {resp.text}")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[-] Send failed: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
if await capture_screenshot():
|
||||||
|
send_screenshot()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
Loading…
Reference in New Issue
Block a user