begin configuration class
This commit is contained in:
parent
d74b082d82
commit
4ebba3388b
|
@ -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,58 +49,61 @@ class Price(object):
|
|||
return False
|
||||
|
||||
class Configuration():
|
||||
def check_location():
|
||||
# setup the config parser
|
||||
config = configparser.ConfigParser()
|
||||
# check whether the config file exists either in the home folder or next to
|
||||
# the binary
|
||||
home = os.getenv('HOME')
|
||||
config_file = "price_checker.cfg"
|
||||
config_folder = ".config/price_checker/"
|
||||
config_path = os.path.join(home, config_folder, config_file)
|
||||
if os.path.isfile(config_path):
|
||||
config.read(config_path)
|
||||
elif os.path.isfile(config_file):
|
||||
config.read(config_file)
|
||||
else:
|
||||
print("Configuration file not found.")
|
||||
sys.exit(1)
|
||||
# assign the repository variable depending whether it's a remote or a local
|
||||
# repository
|
||||
if 'server' in config['DEFAULT']:
|
||||
repository = (config['DEFAULT']['user']
|
||||
+ "@"
|
||||
+ config['DEFAULT']['server']
|
||||
+ ":"
|
||||
+ config['DEFAULT']['repository_path'])
|
||||
int_vars.server = config['DEFAULT']['server']
|
||||
else:
|
||||
repository = config['DEFAULT']['repository_path']
|
||||
# assign the password variable
|
||||
password = config['DEFAULT']['password']
|
||||
# set the environment variables
|
||||
os.environ['BORG_REPO'] = repository
|
||||
os.environ['BORG_PASSPHRASE'] = password
|
||||
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
|
||||
# the binary
|
||||
home = os.getenv('HOME')
|
||||
config_file = "price_checker.cfg"
|
||||
config_folder = ".config/price_checker/"
|
||||
config_path = os.path.join(home, config_folder, config_file)
|
||||
if os.path.isfile(config_path):
|
||||
config.read(config_path)
|
||||
elif os.path.isfile(config_file):
|
||||
config.read(config_file)
|
||||
else:
|
||||
print("Configuration file not found.")
|
||||
sys.exit(1)
|
||||
# assign the repository variable depending whether it's a remote or a local
|
||||
# repository
|
||||
if 'server' in config['DEFAULT']:
|
||||
repository = (config['DEFAULT']['user']
|
||||
+ "@"
|
||||
+ config['DEFAULT']['server']
|
||||
+ ":"
|
||||
+ config['DEFAULT']['repository_path'])
|
||||
int_vars.server = config['DEFAULT']['server']
|
||||
else:
|
||||
repository = config['DEFAULT']['repository_path']
|
||||
# assign the password variable
|
||||
password = config['DEFAULT']['password']
|
||||
# set the environment variables
|
||||
os.environ['BORG_REPO'] = repository
|
||||
os.environ['BORG_PASSPHRASE'] = password
|
||||
|
||||
|
||||
|
||||
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)
|
||||
|
|
Reference in New Issue