Mudiji commited on
Commit
ba8bd07
·
verified ·
1 Parent(s): ff40b8f

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +42 -0
  2. monitor.py +108 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a lightweight Python base image
2
+ FROM python:3.11-slim
3
+
4
+ # Set environment variables
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ PYTHONDONTWRITEBYTECODE=1
7
+
8
+ # Install system dependencies and Google Chrome
9
+ # We need wget, gnupg, and curl to download Chrome
10
+ RUN apt-get update && apt-get install -y \
11
+ wget \
12
+ gnupg \
13
+ unzip \
14
+ curl \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ # Install Google Chrome Stable
18
+ # 1. Download the Google signing key
19
+ # 2. Add the Chrome repository
20
+ # 3. Install Chrome
21
+ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
22
+ && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' \
23
+ && apt-get update \
24
+ && apt-get install -y google-chrome-stable
25
+
26
+ # Check Chrome version (for debugging logs)
27
+ RUN google-chrome --version
28
+
29
+ # Set working directory
30
+ WORKDIR /app
31
+
32
+ # Copy requirements first (to cache dependencies)
33
+ COPY requirements.txt .
34
+
35
+ # Install Python dependencies
36
+ RUN pip install --no-cache-dir -r requirements.txt
37
+
38
+ # Copy the rest of the application code
39
+ COPY monitor.py .
40
+
41
+ # Run the script
42
+ CMD ["python", "monitor.py"]
monitor.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import requests
3
+ from datetime import datetime
4
+ from selenium import webdriver
5
+ from selenium.webdriver.chrome.service import Service
6
+ from selenium.webdriver.chrome.options import Options
7
+ from webdriver_manager.chrome import ChromeDriverManager
8
+
9
+ # --- CONFIGURATION ---
10
+ # Dropbox Link
11
+ URL = "https://www.dropbox.com/scl/fo/jw4g1xg3vkt37ot62paj6/AGUivygf24t-c8vqtWS0gvw?rlkey=we52lnw8bpxepvvurdp7qcgsj&e=26&st=ld16v047&dl=0"
12
+ DISABLED_TEXT = "Link temporarily disabled"
13
+
14
+ # Telegram Config
15
+ TELEGRAM_BOT_TOKEN = "8408121922:AAFcBOLmGrz-jmNHUnH7bJ6VgEl6xZibAnc"
16
+ TELEGRAM_CHAT_ID = "6977971197"
17
+
18
+ def send_telegram_alert(message):
19
+ """Sends a message to your Telegram."""
20
+ try:
21
+ url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
22
+ payload = {
23
+ "chat_id": TELEGRAM_CHAT_ID,
24
+ "text": message,
25
+ "parse_mode": "Markdown"
26
+ }
27
+ response = requests.post(url, json=payload)
28
+ if response.status_code == 200:
29
+ print(">>> Telegram notification sent!")
30
+ else:
31
+ print(f">>> Failed to send Telegram: {response.text}")
32
+ except Exception as e:
33
+ print(f">>> Error sending Telegram: {e}")
34
+
35
+ def get_dropbox_status():
36
+ """Checks the Dropbox link status using Selenium."""
37
+ chrome_options = Options()
38
+ # These flags are CRITICAL for running in Docker/Azure
39
+ chrome_options.add_argument("--headless")
40
+ chrome_options.add_argument("--no-sandbox")
41
+ chrome_options.add_argument("--disable-dev-shm-usage")
42
+ chrome_options.add_argument("--disable-gpu")
43
+ chrome_options.add_argument("--window-size=1920,1080")
44
+
45
+ # User Agent
46
+ 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")
47
+
48
+ driver = None
49
+ try:
50
+ # ChromeDriverManager installs the driver automatically based on the Chrome version in the Docker container
51
+ driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
52
+
53
+ print(f"[{datetime.now().strftime('%H:%M:%S')}] Checking Dropbox link...")
54
+ driver.get(URL)
55
+
56
+ # Wait for JS to load
57
+ time.sleep(10)
58
+
59
+ page_content = driver.page_source
60
+ title = driver.title
61
+
62
+ # 1. Check for Disabled Text
63
+ if DISABLED_TEXT in page_content:
64
+ print(" >>> STATUS: DISABLED ❌")
65
+ return False
66
+
67
+ # 2. Check for Success Indicators (Title contains Dropbox)
68
+ elif "Dropbox" in title:
69
+ print(" >>> STATUS: ENABLED! ✅")
70
+ return True
71
+
72
+ else:
73
+ print(f" >>> WARNING: ambiguous page title: {title}")
74
+ return False
75
+
76
+ except Exception as e:
77
+ print(f" >>> Error during check: {e}")
78
+ # If error occurs, assume false to avoid spamming, or send error log
79
+ return False
80
+
81
+ finally:
82
+ if driver:
83
+ driver.quit()
84
+
85
+ if __name__ == "__main__":
86
+ print("--- Starting Azure Dropbox Monitor ---")
87
+ send_telegram_alert("🤖 Monitor Started! I will check the link every 30 minutes.")
88
+
89
+ while True:
90
+ try:
91
+ is_enabled = get_dropbox_status()
92
+
93
+ if is_enabled:
94
+ msg = (
95
+ "✅ **DROPBOX LINK IS ACTIVE!**\n\n"
96
+ "Go download your files now:\n"
97
+ )
98
+ send_telegram_alert(msg)
99
+
100
+ # Wait a bit longer if found, to avoid spamming yourself every 30 mins?
101
+ # Or keep checking. We'll stick to 30 mins.
102
+
103
+ # Wait 30 minutes
104
+ time.sleep(30 * 60)
105
+
106
+ except Exception as e:
107
+ print(f"Main loop error: {e}")
108
+ time.sleep(60) # Wait 1 min on crash before retrying
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ selenium
2
+ webdriver-manager
3
+ requests