def _parse_current_bill(html): soup = BeautifulSoup(html, 'html.parser') cur_amount = parse_price(soup.find(id='s_4_1_16_0').text.lower()) cur_due = soup.find(id='s_4_1_17_0').text.lower() prev_amount = parse_price(soup.find(id='s_4_1_2_0').text.lower()) prev_due = soup.find(id='s_4_1_3_0').text.lower() return [{ 'amount': prev_amount, 'due': prev_due, 'current': False, }, { 'amount': cur_amount, 'due': cur_due, 'current': True, }]
def _parse_bill_text(text): try: due = re.search(REGEX_DATE, text).group(1) amount = parse_price(re.search(REGEX_AMOUNT, text).group(1)) return (due, amount) except Exception: return (None, None)
def update_ad(): if session["csrf_token"] != request.form["csrf_token"]: return False id = request.form["id"] name = request.form["name"] hinta = request.form["hinta"] kuvaus = request.form["kuvaus"] picture = request.files["picture"] item_owner = get_item_owner(id) if item_owner != get_user_id(): return render_template( "error.html", message="Et voi muokata tätä tuotetta, sillä et omista sitä!") try: hinta = parse_price(hinta) except: return render_template("error.html", message="Hinnan täytyy olla numero") if len(name) > 50 or len(kuvaus) > 150 or hinta > 1000000000: return render_template("error.html", message="Liian pitkä rimpsu informaatiota!") if picture: update_ad_with_picture(name, hinta, kuvaus, picture, id) else: update_ad_without_picture(name, hinta, kuvaus, id) return redirect("/edit_ads")
def make_ad(): if session["csrf_token"] != request.form["csrf_token"]: return False name = request.form["name"] category = request.form["category"] kuvaus = request.form["kuvaus"] hinta = request.form["hinta"] picture = request.files['picture'] try: hinta = parse_price(hinta) except: return render_template("error.html", message="Hinnan täytyy olla numero") if len(name) > 50 or len(kuvaus) > 150 or hinta > 1000000000: return render_template("error.html", message="Liian pitkä rimpsu informaatiota!") pic_name = upload_picture(picture) user_id = get_user_id() if not user_id: return render_template("error.html", message="Et ole kirjautuneena sisään!") item_id = commit_new_ad_to_DB_and_return_item_id(category, name, user_id, hinta, kuvaus, pic_name) return redirect("/item/" + str(item_id))
def scrape_products_data(self) -> List[Tuple[str, float]]: products = self.driver.find_elements_by_xpath('//div[@class="product_wrapper_sub"]') products_data = list() for product in products: name_and_description = product.find_element_by_xpath(".//a[@class='product-name']").text price = product.find_element_by_css_selector("span.price").text price = parse_price(price) products_data.append( (name_and_description, price) ) return products_data
def _parse_bills(html): soup = BeautifulSoup(html, 'html.parser') bills = [] for row in soup.find_all('tr', {'class': 'listRowOff'}): children = row.find_all('span') bill = OrderedDict() bill['start'] = children[1].text bill['end'] = children[2].text bill['usage'] = children[5].text bill['amount'] = parse_price(children[6].text) bills.append(bill) return bills
def _parse_bills(html): soup = BeautifulSoup(html, 'html.parser') bills = [] for row in soup.find( id='ctl00_Main_lvBillHistory_Table1').find_all('tr')[2:]: children = row.find_all('td') bill = OrderedDict() bill['start'] = children[0].text.strip() bill['end'] = children[1].text.strip() bill['usage'] = children[2].text.strip() bill['amount'] = parse_price(children[4].text) bills.append(bill) return bills
def scrape_products_data(self) -> List[Tuple[str, str, float]]: products = self.driver.find_elements_by_xpath(".//div[@class='product-list']") self.wait(4) products_data = list() for product in products: brand_name = product.find_element_by_xpath(".//h2").text product_title = product.find_element_by_xpath(".//*[@class='product-title']").text price = product.find_element_by_xpath(".//strong[@class='price-final']").text price = parse_price(price) products_data.append( (brand_name, product_title, price) ) return products_data