begin configuration class
This commit is contained in:
parent
d74b082d82
commit
4ebba3388b
|
@ -9,7 +9,7 @@ import time
|
||||||
import smtplib
|
import smtplib
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
class User(object):
|
class Email(object):
|
||||||
|
|
||||||
def __init__ (self):
|
def __init__ (self):
|
||||||
self.email = ""
|
self.email = ""
|
||||||
|
@ -31,7 +31,7 @@ class Website(object):
|
||||||
page = requests.get(self.url)
|
page = requests.get(self.url)
|
||||||
self.tree = html.fromstring(page.content)
|
self.tree = html.fromstring(page.content)
|
||||||
|
|
||||||
def extract_current_price(self, string):
|
def extract_price(self, string):
|
||||||
prices = self.tree.xpath(string)
|
prices = self.tree.xpath(string)
|
||||||
return prices
|
return prices
|
||||||
|
|
||||||
|
@ -49,58 +49,61 @@ class Price(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class Configuration():
|
class Configuration():
|
||||||
def check_location():
|
def __init__ (self):
|
||||||
# setup the config parser
|
self.check_location()
|
||||||
config = configparser.ConfigParser()
|
|
||||||
# check whether the config file exists either in the home folder or next to
|
def check_location(self):
|
||||||
# the binary
|
# setup the config parser
|
||||||
home = os.getenv('HOME')
|
config = configparser.ConfigParser()
|
||||||
config_file = "price_checker.cfg"
|
# check whether the config file exists either in the home folder or next to
|
||||||
config_folder = ".config/price_checker/"
|
# the binary
|
||||||
config_path = os.path.join(home, config_folder, config_file)
|
home = os.getenv('HOME')
|
||||||
if os.path.isfile(config_path):
|
config_file = "price_checker.cfg"
|
||||||
config.read(config_path)
|
config_folder = ".config/price_checker/"
|
||||||
elif os.path.isfile(config_file):
|
config_path = os.path.join(home, config_folder, config_file)
|
||||||
config.read(config_file)
|
if os.path.isfile(config_path):
|
||||||
else:
|
config.read(config_path)
|
||||||
print("Configuration file not found.")
|
elif os.path.isfile(config_file):
|
||||||
sys.exit(1)
|
config.read(config_file)
|
||||||
# assign the repository variable depending whether it's a remote or a local
|
else:
|
||||||
# repository
|
print("Configuration file not found.")
|
||||||
if 'server' in config['DEFAULT']:
|
sys.exit(1)
|
||||||
repository = (config['DEFAULT']['user']
|
# assign the repository variable depending whether it's a remote or a local
|
||||||
+ "@"
|
# repository
|
||||||
+ config['DEFAULT']['server']
|
if 'server' in config['DEFAULT']:
|
||||||
+ ":"
|
repository = (config['DEFAULT']['user']
|
||||||
+ config['DEFAULT']['repository_path'])
|
+ "@"
|
||||||
int_vars.server = config['DEFAULT']['server']
|
+ config['DEFAULT']['server']
|
||||||
else:
|
+ ":"
|
||||||
repository = config['DEFAULT']['repository_path']
|
+ config['DEFAULT']['repository_path'])
|
||||||
# assign the password variable
|
int_vars.server = config['DEFAULT']['server']
|
||||||
password = config['DEFAULT']['password']
|
else:
|
||||||
# set the environment variables
|
repository = config['DEFAULT']['repository_path']
|
||||||
os.environ['BORG_REPO'] = repository
|
# assign the password variable
|
||||||
os.environ['BORG_PASSPHRASE'] = password
|
password = config['DEFAULT']['password']
|
||||||
|
# set the environment variables
|
||||||
|
os.environ['BORG_REPO'] = repository
|
||||||
|
os.environ['BORG_PASSPHRASE'] = password
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
christian = User()
|
email = Email()
|
||||||
tui = Website()
|
website = Website()
|
||||||
budget = Price()
|
price = Price()
|
||||||
|
|
||||||
christian.prompt_for_email()
|
email.prompt_for_email()
|
||||||
tui.prompt_for_url()
|
website.prompt_for_url()
|
||||||
budget.prompt_for_amount()
|
price.prompt_for_amount()
|
||||||
tui.get_page()
|
website.get_page()
|
||||||
current_price = tui.extract_current_price('//div[@class="product-price"]'
|
current_price = website.extract_price('//div[@class="product-price"]'
|
||||||
'/text()')
|
'/text()')
|
||||||
|
|
||||||
while not budget.compare_prices(current_price):
|
while not budget.compare_prices(current_price):
|
||||||
tui.get_page()
|
website.get_page()
|
||||||
current_price = tui.extract_current_price('//div[@class="product-price"]'
|
current_price = website.extract_price('//div[@class="product-price"]'
|
||||||
'/text()')
|
'/text()')
|
||||||
print ('[%s]' % ', '.join(map(str, current_price)))
|
print ('[%s]' % ', '.join(map(str, current_price)))
|
||||||
result = budget.compare_prices(current_price)
|
result = price.compare_prices(current_price)
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
else:
|
else:
|
||||||
print (tui.url)
|
print (tui.url)
|
||||||
|
|
Reference in New Issue