orange-bot / main.py
beverlyhills's picture
Update main.py
4a4c564 verified
Raw
History Blame Contribute Delete
2.47 kB
import time
import os
import requests
import config # Ensure BOT_TOKEN, CHAT_ID, etc., are in config.py
# Keep all your original imports here
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# --- 1. THE ENGINE (Required for Hugging Face) ---
def get_driver():
chrome_options = Options()
chrome_options.add_argument("--headless=new")
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")
chrome_options.binary_location = "/usr/bin/google-chrome"
service = Service(ChromeDriverManager().install())
return webdriver.Chrome(service=service, options=chrome_options)
def send_telegram_msg(text):
url = f"https://api.telegram.org/bot{config.BOT_TOKEN}/sendMessage"
payload = {"chat_id": config.CHAT_ID, "text": text}
try:
requests.post(url, json=payload)
except Exception as e:
print(f"Telegram Error: {e}")
# --- 2. YOUR BOT LOGIC ---
def run_bot_logic(driver):
"""
PASTE YOUR ORIGINAL BOT CODE HERE.
(The parts that check numbers, forward OTPs, and click buttons)
"""
print("[πŸš€] Navigation started...")
driver.get("https://www.orangecarrier.com/login")
# Apply your cookies from config.py
driver.add_cookie({'name': 'XSRF-TOKEN', 'value': config.XSRF_TOKEN})
driver.add_cookie({'name': 'orange_carrier_session', 'value': config.SESSION_ID})
driver.refresh()
time.sleep(5)
# --- YOUR CUSTOM LOOP STARTS HERE ---
# Example: while True: check_new_calls(driver)
print("[βœ…] Monitoring active...")
while True:
# Put your specific number checking/OTP logic here
time.sleep(30)
# --- 3. THE STARTUP ---
if __name__ == "__main__":
print("[πŸš€] Starting Orange Carrier Monitor...")
driver = get_driver()
try:
run_bot_logic(driver)
except Exception as e:
print(f"[πŸ’₯] Fatal error: {e}")
send_telegram_msg(f"⚠️ Bot crashed: {e}")
finally:
driver.quit()
print("[*] Monitoring stopped")