-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.py
More file actions
32 lines (30 loc) · 1.31 KB
/
Copy pathmonitor.py
File metadata and controls
32 lines (30 loc) · 1.31 KB
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
from scraper import get_product_from_url
from database import get_active_products, init_db, get_last_price, save_price, get_users
from notifier import send_email_alert, send_telegram_alert
def run_monitor():
init_db()
users = get_users()
print(f"Usuarios encontrados: {len(users) if users else 0}")
for i in users:
user_id = i[0]
user_email = i[1]
user_chat_id = i[3]
products = get_active_products(user_id)
print(f"Productos para usuario {user_id}: {len(products) if products else 0}")
if not products:
print("No hay productos activos")
continue
for product in products:
result = get_product_from_url(product[1])
if result is None:
print(f'No se pudo obtener el precio de {product[2]}, saltando...')
continue
name, price, image_url = result
last_price = get_last_price(product[1], user_id)
if last_price:
if price != last_price:
send_telegram_alert(name , price, last_price, product[1], image_url, user_chat_id)
send_email_alert(name, price, last_price, product[1], user_email, image_url)
save_price(product[1], product[2], price, user_id)
if __name__ == "__main__":
run_monitor()