add a while loop

This commit is contained in:
Andreas Zweili 2017-03-12 16:15:49 +01:00
parent f10bdb556b
commit 2725b5c771
1 changed files with 39 additions and 8 deletions

View File

@ -5,6 +5,7 @@
from lxml import html
import requests
import time
class User(object):
@ -13,26 +14,56 @@ class User(object):
def prompt_for_email(self):
self.email = input("Please enter your email address:")
return self.email
class Website(object):
def __init__ (self):
self.url = ""
self.tree = ""
def prompt_for_url(self):
url = input("Please enter the url you want to monitor:")
self.url = input("Please enter the url you want to monitor:")
def get_page(self, url):
page = requests.get(url)
tree = html.fromstring(page.content)
return self.tree
def get_page(self):
page = requests.get(self.url)
self.tree = html.fromstring(page.content)
def extract_current_price(self, string):
prices = self.tree.xpath(string)
return prices
class Price(object):
def __init__ (self):
self.desired_price = ""
def prompt_for_price(self):
desired_price = input("Please enter the price
you're looking for:")
def prompt_for_amount(self):
self.desired_price = input("Please enter the price "
"you're looking for:")
def compare_prices(self, current_price):
if not self.desired_price in current_price:
return False
christian = User()
tui = Website()
budget = Price()
christian.prompt_for_email()
tui.prompt_for_url()
budget.prompt_for_amount()
tui.get_page()
current_price = tui.extract_current_price('//div[@class="product-price"]'
'/text()')
while not budget.compare_prices(current_price):
tui.get_page()
current_price = tui.extract_current_price('//div[@class="product-price"]'
'/text()')
print ('[%s]' % ', '.join(map(str, current_price)))
result = budget.compare_prices(current_price)
time.sleep(60)