File size: 4,003 Bytes
ba8bd07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import time
import requests
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

# --- CONFIGURATION ---
# Dropbox Link
URL = "https://www.dropbox.com/scl/fo/jw4g1xg3vkt37ot62paj6/AGUivygf24t-c8vqtWS0gvw?rlkey=we52lnw8bpxepvvurdp7qcgsj&e=26&st=ld16v047&dl=0"
DISABLED_TEXT = "Link temporarily disabled"

# Telegram Config
TELEGRAM_BOT_TOKEN = "8408121922:AAFcBOLmGrz-jmNHUnH7bJ6VgEl6xZibAnc"
TELEGRAM_CHAT_ID = "6977971197"

def send_telegram_alert(message):
    """Sends a message to your Telegram."""
    try:
        url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
        payload = {
            "chat_id": TELEGRAM_CHAT_ID,
            "text": message,
            "parse_mode": "Markdown"
        }
        response = requests.post(url, json=payload)
        if response.status_code == 200:
            print(">>> Telegram notification sent!")
        else:
            print(f">>> Failed to send Telegram: {response.text}")
    except Exception as e:
        print(f">>> Error sending Telegram: {e}")

def get_dropbox_status():
    """Checks the Dropbox link status using Selenium."""
    chrome_options = Options()
    # These flags are CRITICAL for running in Docker/Azure
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-dev-shm-usage")
    chrome_options.add_argument("--disable-gpu")
    chrome_options.add_argument("--window-size=1920,1080")
    
    # User Agent
    chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36")

    driver = None
    try:
        # ChromeDriverManager installs the driver automatically based on the Chrome version in the Docker container
        driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
        
        print(f"[{datetime.now().strftime('%H:%M:%S')}] Checking Dropbox link...")
        driver.get(URL)
        
        # Wait for JS to load
        time.sleep(10)
        
        page_content = driver.page_source
        title = driver.title

        # 1. Check for Disabled Text
        if DISABLED_TEXT in page_content:
            print("   >>> STATUS: DISABLED ❌")
            return False
        
        # 2. Check for Success Indicators (Title contains Dropbox)
        elif "Dropbox" in title:
            print("   >>> STATUS: ENABLED! ✅")
            return True
            
        else:
            print(f"   >>> WARNING: ambiguous page title: {title}")
            return False

    except Exception as e:
        print(f"   >>> Error during check: {e}")
        # If error occurs, assume false to avoid spamming, or send error log
        return False
        
    finally:
        if driver:
            driver.quit()

if __name__ == "__main__":
    print("--- Starting Azure Dropbox Monitor ---")
    send_telegram_alert("🤖 Monitor Started! I will check the link every 30 minutes.")

    while True:
        try:
            is_enabled = get_dropbox_status()
            
            if is_enabled:
                msg = (
                    "✅ **DROPBOX LINK IS ACTIVE!**\n\n"
                    "Go download your files now:\n"
                )
                send_telegram_alert(msg)
                
                # Wait a bit longer if found, to avoid spamming yourself every 30 mins?
                # Or keep checking. We'll stick to 30 mins.
            
            # Wait 30 minutes
            time.sleep(30 * 60)
            
        except Exception as e:
            print(f"Main loop error: {e}")
            time.sleep(60) # Wait 1 min on crash before retrying