Skip to content

Commit

Permalink
Added --mode = fast/slow
Browse files Browse the repository at this point in the history
  • Loading branch information
zdeneklapes committed Jan 2, 2024
1 parent 2272495 commit 81c0778
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion bazos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
from pathlib import Path
import sys
from typing import Dict, Any, Callable
from typing import Any, Callable, Dict
from distutils.util import strtobool # noqa

from bazos.scrapper import BazosScrapper, BazosUser, BazosDriver
Expand Down Expand Up @@ -38,6 +38,13 @@ def parse_cli_argument() -> Dict[str, Any]:
parser.add_argument('--remote',
**BOOL_AS_STR_ARGUMENTS_FALSE,
help='Use remote')
# Possible values: fast, slow
parser.add_argument('--mode',
type=str,
choices=['fast', 'slow'],
default='fast',
nargs='?',
help='Mode')
# ?
parser.add_argument('--items-path',
type=Path,
Expand Down Expand Up @@ -80,6 +87,7 @@ def main():
# Print arguments
if args['verbose']:
print(' '.join(sys.argv))
print(args)

bazos_driver = BazosDriver(args=args, country='cz')
for country in args['country']:
Expand Down
10 changes: 9 additions & 1 deletion bazos/scrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from bazos.core import settings
from bazos.info.product import Product, get_all_products
from bazos.info.rubric_category import get_rubric, get_category
from bazos.shared.utils import parse_yaml
from bazos.shared.utils import parse_yaml, wait_random_time


################################################################################
Expand Down Expand Up @@ -214,6 +214,8 @@ def delete_advertisement(self):
pwd_input = self.driver.find_element(By.XPATH, XPathsBazos.delete_pwd_input)
pwd_input.clear()
pwd_input.send_keys(getattr(self.user, 'password'))
if self.args['mode'] == 'slow':
wait_random_time(coef=1)
self.driver.find_element(By.XPATH, XPathsBazos.delete_submit).click() # Submit-Delete

def delete_all_advertisements(self):
Expand All @@ -222,6 +224,8 @@ def delete_all_advertisements(self):
if self.args['verbose']:
print("==> Removing old advertisements")
for i in range(self.advertisements):
if self.args['mode'] == 'slow':
wait_random_time(coef=1)
element = self.driver.find_element(By.CLASS_NAME, 'nadpis')
if self.args['verbose']:
print(f"Removing[{i}/{self.advertisements}]: {element.text}")
Expand Down Expand Up @@ -256,6 +260,8 @@ def create_advertisement(self, product: Product):
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 self.args['mode'] == 'slow':
wait_random_time(coef=1)
self.driver.find_element(By.XPATH, XPathsBazos.product_submit).click()

def create_all_advertisements(self) -> None:
Expand All @@ -265,6 +271,8 @@ def create_all_advertisements(self) -> None:
if self.args['verbose']:
print("==> Adding advertisements")
for idx, product in enumerate(products):
if self.args['mode'] == 'slow':
wait_random_time(coef=1)

if self.product_already_advertised(product):
if self.args['verbose']:
Expand Down

0 comments on commit 81c0778

Please sign in to comment.