Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: various improvements #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bazos/info/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def __init__(self, product_path: str):
self.currency_rates = CurrencyRates()

def get_images(self):
if not path.isdir(path.join(self.product_path, 'photos')):
return []

images = sorted(map(lambda x: path.join(self.product_path, 'photos', x),
next(os.walk(path.join(self.product_path, 'photos')))[2]))
return [filename for filename in images if
Expand Down Expand Up @@ -76,7 +79,7 @@ def load_product_info(self, *, product_dir):
line=line)
continue

if line.replace(' ', '').replace('\t', '').replace('\n', '') == '':
if line.replace(' ', '').replace('\t', '').replace('\n', '') == '' and current_product_info_key != 'description':
continue

if product_info[current_product_info_key] == product_info['rubric']:
Expand Down
18 changes: 12 additions & 6 deletions bazos/scrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def click_submit_by_value(submits: [WebElement], value: str):
class XPathsBazos:
select_rubrik = "//div[@class='maincontent']/div[1]/form/select"
select_category = "//div[@class='maincontent']/form/div[1]/select"
user_inputs = "//div[@class='maincontent']/form/input"
user_inputs = "//div[@class='maincontent']/form[2]/input"
delete_pwd_input = "//div[@class='maincontent']/div[2]/form/input[1]" # nosec
delete_submit = "//div[@class='maincontent']/div[2]/form/input[4]"

auth_phone_input = "//div[@class='maincontent']/form/input[2]"
auth_phone_input = "//div[@class='maincontent']/form[2]/input[2]"
auth_phone_check_submit = "//div[@class='maincontent']/form/input[4]"
auth_code_input = "//div[@class='maincontent']/div[1]/form/input[1]"
auth_code_submit = "//div[@class='maincontent']/div[1]/form/input[3]"
Expand Down Expand Up @@ -233,7 +233,11 @@ def add_advertisement(self, product: Product):
select_category.select_by_visible_text(get_category(self.country, product.rubric, product.category))
self.driver.find_element(By.ID, 'nadpis').send_keys(product.title)
self.driver.find_element(By.ID, 'popis').send_keys(product.description)
self.driver.find_element(By.ID, 'cena').send_keys(product.get_location_price(self.country))

if product.price.isnumeric():
self.driver.find_element(By.ID, 'cena').send_keys(product.price)
else:
Select(self.driver.find_element(By.ID, 'cenavyber')).select_by_visible_text(product.price)

self.driver.find_element(By.ID, 'lokalita').clear()
self.driver.find_element(By.ID, 'lokalita').send_keys(getattr(self.user, 'psc'))
Expand All @@ -247,7 +251,9 @@ def add_advertisement(self, product: Product):
self.driver.find_element(By.ID, 'heslobazar').send_keys(getattr(self.user, 'password'))

self.driver.find_element(By.CLASS_NAME, 'ovse').click()
self.driver.find_element(By.XPATH, XPathsBazos.product_img_input).send_keys('\n'.join(product.images))

if product.images:
self.driver.find_element(By.XPATH, XPathsBazos.product_img_input).send_keys('\n'.join(product.images))

self.driver.find_element(By.XPATH, XPathsBazos.product_submit).click()

Expand All @@ -261,11 +267,11 @@ def create_advertisements(self) -> None:

if self.product_already_advertised(product):
if self.args['verbose']:
print(f"Skipping[{idx}/{self.advertisements}]: {product.product_path}")
print(f"Skipping[{idx + 1}/{self.advertisements}]: {product.product_path}")
continue

if self.args['verbose']:
print(f"Adding[{idx}/{self.advertisements}]: {product.product_path}")
print(f"Adding[{idx + 1}/{self.advertisements}]: {product.product_path}")

# product not advertised ADD them
self.driver.find_element(By.CLASS_NAME, 'pridati').click() # go to add page
Expand Down