bidm / app.py
huijio's picture
Create app.py
e3e29b7 verified
import requests
from bs4 import BeautifulSoup
import time
import re
import os
from datetime import datetime
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
class AdShareTracker:
def __init__(self):
self.current_bid = None
self.bot_token = "8439342017:AAEmRrBp-AKzVK6cbRdHekDGSpbgi7aH5Nc"
self.chat_id = "2052085789"
self.session = requests.Session()
self.email = "s.an.t.o.smaic.a36.9@gmail.com"
self.password = "s.an.t.o.smaic.a36.9@gmail.com"
# Set headers to look like a real browser
self.session.headers.update({
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
})
def send_telegram(self, message):
"""Send Telegram message"""
try:
url = f"https://api.telegram.org/bot{self.bot_token}/sendMessage"
data = {
"chat_id": self.chat_id,
"text": message,
"parse_mode": "HTML"
}
response = self.session.post(url, data=data, timeout=30)
if response.status_code == 200:
logger.info("πŸ“± Telegram sent")
return True
return False
except Exception as e:
logger.error(f"Telegram error: {e}")
return False
def login_to_adshare(self):
"""Login to AdShare and maintain session"""
try:
login_url = "https://adsha.re/login"
# First, get the login page to capture any cookies
logger.info("πŸ” Getting login page...")
response = self.session.get(login_url, timeout=30)
if response.status_code != 200:
logger.error(f"❌ Failed to get login page: {response.status_code}")
return False
# Prepare login data
login_data = {
'email': self.email,
'password': self.password,
# Add any hidden form fields if needed
}
# Submit login form
logger.info("πŸ” Attempting login...")
response = self.session.post(login_url, data=login_data, timeout=30)
# Check if login was successful by trying to access a protected page
test_url = "https://adsha.re/adverts/create"
response = self.session.get(test_url, timeout=30)
if response.status_code == 200 and "adverts/create" in response.url:
logger.info("βœ… Login successful!")
return True
else:
logger.error("❌ Login failed - redirected or wrong page")
return False
except Exception as e:
logger.error(f"❌ Login error: {e}")
return False
def get_top_bid(self):
"""Get current top bid after login"""
try:
create_url = "https://adsha.re/adverts/create"
logger.info("πŸ” Fetching bid page...")
response = self.session.get(create_url, timeout=30)
if response.status_code != 200:
logger.error(f"❌ Page fetch failed: {response.status_code}")
# Try to re-login if session expired
if "login" in response.url:
logger.info("πŸ”„ Session expired, re-logging in...")
if self.login_to_adshare():
response = self.session.get(create_url, timeout=30)
else:
return None
soup = BeautifulSoup(response.content, 'html.parser')
# Look for the bid information
for element in soup.find_all(string=re.compile(r'top bid is \d+ credits')):
match = re.search(r'top bid is (\d+) credits', element)
if match:
bid = int(match.group(1))
logger.info(f"βœ… Current bid: {bid} credits")
return bid
# Alternative search methods
labels = soup.find_all('div', class_='label')
for label in labels:
if 'top bid' in label.get_text():
match = re.search(r'(\d+) credits', label.get_text())
if match:
bid = int(match.group(1))
logger.info(f"βœ… Found bid via label: {bid} credits")
return bid
logger.warning("❌ Could not find bid information")
return None
except Exception as e:
logger.error(f"❌ Error getting bid: {e}")
return None
def start_tracking(self):
"""Main tracking function"""
logger.info("πŸš€ Starting AdShare Bid Tracker with Login...")
# Send startup message
self.send_telegram("πŸ€– <b>AdShare Bid Tracker Starting...</b>")
# Login first
if not self.login_to_adshare():
self.send_telegram("❌ <b>Login failed! Check credentials.</b>")
logger.error("❌ Cannot continue without login")
return
self.send_telegram("βœ… <b>Login successful! Starting monitoring...</b>")
# Get initial bid
self.current_bid = self.get_top_bid()
if self.current_bid:
self.send_telegram(f"🎯 <b>Current Top Bid: {self.current_bid} credits</b>")
logger.info(f"🎯 Initial bid: {self.current_bid} credits")
else:
self.send_telegram("❌ <b>Could not get initial bid</b>")
logger.error("❌ Failed to get initial bid")
return
# Main monitoring loop
check_count = 0
while True:
try:
time.sleep(300) # 5 minutes
check_count += 1
logger.info(f"πŸ” Check #{check_count}...")
new_bid = self.get_top_bid()
if new_bid:
if new_bid != self.current_bid:
logger.info(f"🚨 BID CHANGED: {self.current_bid} β†’ {new_bid}")
message = f"""🚨 <b>BID CHANGED!</b>
πŸ“Š Before: {self.current_bid} credits
πŸ“Š After: {new_bid} credits
πŸ“ˆ Change: {new_bid - self.current_bid} credits
πŸ•’ Time: {datetime.now().strftime('%H:%M:%S')}
πŸ”— https://adsha.re/adverts/create"""
if self.send_telegram(message):
self.current_bid = new_bid
else:
logger.info(f"βœ… No change: {new_bid} credits")
# Send status every 12 checks (1 hour)
if check_count % 12 == 0:
self.send_telegram(f"πŸ“Š <b>Status Update:</b> Still monitoring - {new_bid} credits after {check_count} checks")
else:
logger.warning("❌ Failed to fetch bid - will retry")
except KeyboardInterrupt:
logger.info("πŸ›‘ Tracker stopped by user")
break
except Exception as e:
logger.error(f"❌ Loop error: {e}")
time.sleep(60)
if __name__ == "__main__":
tracker = AdShareTracker()
tracker.start_tracking()