begin configuration class

This commit is contained in:
Andreas Zweili 2017-03-13 13:06:21 +01:00
parent d74b082d82
commit 4ebba3388b
1 changed files with 48 additions and 45 deletions

View File

@ -9,7 +9,7 @@ import time
import smtplib
import configparser
class User(object):
class Email(object):
def __init__ (self):
self.email = ""
@ -31,7 +31,7 @@ class Website(object):
page = requests.get(self.url)
self.tree = html.fromstring(page.content)
def extract_current_price(self, string):
def extract_price(self, string):
prices = self.tree.xpath(string)
return prices
@ -49,7 +49,10 @@ class Price(object):
return False
class Configuration():
def check_location():
def __init__ (self):
self.check_location()
def check_location(self):
# setup the config parser
config = configparser.ConfigParser()
# check whether the config file exists either in the home folder or next to
@ -84,23 +87,23 @@ class Configuration():
christian = User()
tui = Website()
budget = Price()
email = Email()
website = Website()
price = 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"]'
email.prompt_for_email()
website.prompt_for_url()
price.prompt_for_amount()
website.get_page()
current_price = website.extract_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"]'
website.get_page()
current_price = website.extract_price('//div[@class="product-price"]'
'/text()')
print ('[%s]' % ', '.join(map(str, current_price)))
result = budget.compare_prices(current_price)
result = price.compare_prices(current_price)
time.sleep(60)
else:
print (tui.url)