import ctypes
import time
from playwright.sync_api import sync_playwright
USERNAME = "hoangchan"
PASSWORD = "ab270894"
LOGIN_URL = "https://forum.vdevs.net/login/"
FARM_URL = "https://forum.vdevs.net/farm/star-fruit-tree"
# --- 1. Ẩn cửa sổ CMD ngay khi khởi động ---
def hide_console():
try:
hwnd = ctypes.windll.kernel32.GetConsoleWindow()
if hwnd:
ctypes.windll.user32.ShowWindow(hwnd, 0)
except Exception:
pass
# Gọi ẩn console ngay lập tức
hide_console()
# --- 2. Thao tác Thu Hoạch ---
def run_harvest_job():
"""Thực hiện quy trình đăng nhập và thu hoạch cây khế."""
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
context = browser.new_context(
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
)
page = context.new_page()
try:
# Đăng nhập
page.goto(LOGIN_URL, wait_until="domcontentloaded", timeout=60000)
page.fill("#account", USERNAME)
page.fill("#password", PASSWORD)
page.click("input[type='submit'][value='Đăng nhập']")
page.wait_for_load_state("domcontentloaded")
# Truy cập trang Cây khế
page.goto(FARM_URL, wait_until="domcontentloaded", timeout=60000)
# Thực hiện Thu hoạch
harvest_button = page.locator("input[type='submit'][value='Thu hoạch']")
if harvest_button.count() > 0:
harvest_button.click()
page.wait_for_timeout(3000)
except Exception:
pass
finally:
browser.close()
# --- 3. Vòng lặp 6 giờ ---
def main():
while True:
run_harvest_job()
# Chờ 6 giờ (21,600 giây) trước khi chạy lượt thu hoạch tiếp theo
time.sleep(21600)
if __name__ == "__main__":
main()