Skip to content

Commit 6db68e1

Browse files
authored
Create price_product
1 parent 10a0de1 commit 6db68e1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

hack

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import requests
3+
from bs4 import BeautifulSoup
4+
import time
5+
6+
class PriceTracker:
7+
def __init__(self):
8+
self.products = {}
9+
10+
def add_product(self, product_name, url, target_price):
11+
self.products[product_name] = (url, target_price)
12+
print(f"Tracking {product_name} at {url} with target price ${target_price}.")
13+
14+
def check_prices(self):
15+
for product_name, (url, target_price) in self.products.items():
16+
response = requests.get(url)
17+
soup = BeautifulSoup(response.text, 'html.parser')
18+
price_tag = soup.find('span', class_='price') # Adjust based on actual site
19+
if price_tag:
20+
current_price = float(price_tag.text.replace('$', '').replace(',', ''))
21+
if current_price <= target_price:
22+
print(f"ALERT: {product_name} is now ${current_price}!")
23+
else:
24+
print(f"{product_name} is still ${current_price}.")
25+
26+
def start_tracking(self):
27+
while True:
28+
self.check_prices()
29+
time.sleep(3600) # Check every hour
30+
31+
def main():
32+
tracker = PriceTracker()
33+
34+
while True:
35+
product_name = input("\nEnter the product name (or 'quit' to exit): ")
36+
if product_name.lower() == 'quit':
37+
break
38+
url = input("Enter the product URL: ")
39+
target_price = float(input("Enter your target price: "))
40+
tracker.add_product(product_name, url, target_price)
41+
42+
tracker.start_tracking()
43+
44+
if __name__ == "__main__":
45+
main()

0 commit comments

Comments
 (0)