def create_alert(store_id): if request.method == 'POST': name = request.form['name'] url = request.form['url'] price_limit = Utils.get_price_float(request.form['price_limit']) item = Item(name, url, store_id) item.save_to_mongo() alert = Alert(session['email'], price_limit, item._id) alert.load_item_price() return render_template("alerts/new_alert.html", store_id=store_id)
def edit_alert(alert_id): if request.method == 'POST': price_limit = Utils.get_price_float(request.form['price_limit']) alert = Alert.find_by_id(alert_id) alert.price_limit = price_limit alert.load_item_price() return redirect(url_for('.get_alert_page', alert_id=alert_id)) # METHOD GET return render_template("alerts/edit_alert.html", alert=Alert.find_by_id(alert_id))
def load_price(self): request = requests.get(self.url) content = request.content soup = BeautifulSoup(content, "html.parser") element = soup.find(self.tag_name, self.query) #amazon # element = soup.find("span", {"id": "price_inside_buybox","class": "a-size-medium a-color-price"}) string_price = element.text.strip() pattern = re.compile("[0-9]+([,.][0-9]+)+") # get the price match = pattern.search(string_price) self.price = Utils.get_price_float(match.group()) return self.price