test commit

This commit is contained in:
Andreas Zweili 2017-03-14 16:16:07 +01:00
parent 9c19ec21b2
commit c09f5d6e05
1 changed files with 25 additions and 21 deletions

View File

@ -10,6 +10,8 @@ import smtplib
import os import os
import sys import sys
import configparser import configparser
import dryscrape
import lxml
class Email(object): class Email(object):
@ -28,9 +30,11 @@ class Email(object):
message = "Subject: " + message message = "Subject: " + message
try: try:
self.server.sendmail(sender, self.recipient, message) self.server.sendmail(sender, self.recipient, message)
self.server.quit()
print("Successfully sent email") print("Successfully sent email")
except SMTPException: except SMTPException:
print("Error: unable to send email") print("Error: unable to send email")
self.server.quit()
class Website(object): class Website(object):
@ -39,11 +43,14 @@ class Website(object):
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): def get_page(self):
#session = dryscrape.Session()
#session.visit(self.url)
#page = session.body()
page = requests.get(self.url) page = requests.get(self.url)
self.tree = html.fromstring(page.content) self.soup = BeautifulSoup(page.text, "lxml")
def extract_price(self, string): def extract_price(self):
prices = self.tree.xpath(string) prices = self.soup.find_all("div", class_="product-price")
return prices return prices
@ -93,26 +100,23 @@ class Configuration():
settings = Configuration() settings = Configuration()
email = Email() #email = Email()
#website = Website() website = Website()
#price = Price() #price = Price()
current_price = "" #current_price = ""
message = "Test" #message = "Test"
print(settings.password) website.get_page()
print(settings.smtp_server) print(website.extract_price())
print(settings.smtp_port)
print(settings.sender_address)
email.connecting(settings.smtp_server, settings.smtp_port)
email.login(settings.sender_address, settings.password)
email.sending(settings.sender_address, message)
#while not price.compare(current_price): #while not price.compare(current_price):
# website.get_page() # website.get_page()
# current_price = website.extract_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 = price.compare(current_price) # result = price.compare(current_price)
# time.sleep(60) # time.sleep(60)
#else: #else:
# print(website.url) # email.connecting(settings.smtp_server, settings.smtp_port)
# email.login(settings.sender_address, settings.password)
# email.sending(settings.sender_address, message)