Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
zdeneklapes committed Dec 26, 2023
1 parent 553f009 commit 98021e9
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 160 deletions.
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ ENV TZ "US/Eastern"
RUN echo "US/Eastern" | tee /etc/timezone
RUN dpkg-reconfigure --frontend noninteractive tzdata

# Install utilities
## Install utilities
RUN apt-get -yqq install ca-certificates curl dnsutils man openssl unzip wget

# Install xvfb and fonts
## Install xvfb and fonts
RUN apt-get -yqq install xvfb fonts-ipafont-gothic xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic

# Install Fluxbox (window manager)
## Install Fluxbox (window manager)
RUN apt-get -yqq install fluxbox

# Install VNC
Expand Down Expand Up @@ -136,4 +136,5 @@ EXPOSE 4444 5900
ENV DISPLAY=:99

WORKDIR /app
CMD ["/app/make.sh", "entrypoint"]
CMD ["fish"]
#CMD ["/app/make.sh", "entrypoint"]
3 changes: 3 additions & 0 deletions Hub/example-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[router]
username = "admin"
password = "admin"
95 changes: 49 additions & 46 deletions bazos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from pathlib import Path
import sys
from typing import Dict, Any
from distutils.util import strtobool # noqa

from bazos.main import BazosScrapper, BazosUser
from bazos.scrapper import BazosScrapper, BazosUser, BazosDriver

__version__ = "0.1.0"
__apiversion__ = "0.1.0"
Expand All @@ -13,31 +14,34 @@

def parse_cli_argument() -> Dict[str, Any]:
parser = argparse.ArgumentParser()
BOOL_AS_STR_ARGUMENTS_for_parser_add_argument = dict(
type=lambda x: bool(strtobool(x)), default=False, nargs="?", const=True
)
# true/false
parser.add_argument('--login',
action='store_true',
**BOOL_AS_STR_ARGUMENTS_for_parser_add_argument,
help='Login to bazos')
parser.add_argument('--bazos',
action='store_true',
**BOOL_AS_STR_ARGUMENTS_for_parser_add_argument,
help='Use bazos')
parser.add_argument('--add-only',
action='store_true',
**BOOL_AS_STR_ARGUMENTS_for_parser_add_argument,
help='Add only new products, not remove old ones')
parser.add_argument('--print-rubrics',
action='store_true',
**BOOL_AS_STR_ARGUMENTS_for_parser_add_argument,
help='Print rubrics')
parser.add_argument("--verbose",
action='store_true',
default=True,
**BOOL_AS_STR_ARGUMENTS_for_parser_add_argument,
help='Verbose')
parser.add_argument("--delete-all",
action='store_true',
default=True,
**BOOL_AS_STR_ARGUMENTS_for_parser_add_argument,
help='Verbose')
parser.add_argument("--create-all",
action='store_true',
default=True,
**BOOL_AS_STR_ARGUMENTS_for_parser_add_argument,
help='Verbose')
parser.add_argument('--remote',
**BOOL_AS_STR_ARGUMENTS_for_parser_add_argument,
help='Use remote')
# ?
parser.add_argument('--items-path',
type=Path,
Expand All @@ -54,59 +58,58 @@ def parse_cli_argument() -> Dict[str, Any]:
nargs="+",
help="What bazos country to use",
default=['cz', 'sk'])
cli_args = vars(parser.parse_args())
return cli_args
args = vars(parser.parse_args())
return args


def main():
cli_args = parse_cli_argument()
args = parse_cli_argument()

if cli_args['verbose']:
# print(f"==> CLI args: {cli_args}")
# Print arguments
if args['verbose']:
print(' '.join(sys.argv))

if cli_args['login']:
bazos_user = BazosUser(
country='cz', items_path=cli_args['items_path'],
credentials_path=cli_args['credentials_path']
)
# Driver
bazos_driver = BazosDriver(args=args, country='cz')

# Login
if args['login']:
bazos_user = BazosUser(country='cz', args=args, driver=bazos_driver.driver)
bazos_user.authenticate()
bazos_user.save_user_credentials()
else:
bazos_user = BazosUser(country='cz', args=args, driver=bazos_driver.driver)
bazos_user.exists_user_credentials()

# Rubrics
if args['print_rubrics']:
for country in args['country']:
bazos_user = BazosUser(country=country, args=args, driver=bazos_driver.driver)
bazos_scrapper = BazosScrapper(country=country, args=args, user=bazos_user, driver=bazos_driver.driver)
bazos_scrapper.load_page_with_cookies()
bazos_scrapper.print_all_rubrics_and_categories()

if cli_args['bazos']:
for country in cli_args['country']:
if cli_args['verbose']:
# Bazos
if args['bazos']:
for country in args['country']:
bazos_user = BazosUser(country=country, args=args, driver=bazos_driver.driver)

if args['verbose']:
print(f"==> Processing country: {country}")

# Check if user credentials exists
user = BazosUser(
country='cz', items_path=cli_args['items_path'],
credentials_path=cli_args['credentials_path']
)
try:
user.exists_user_credentials(raise_exception=True)
except FileNotFoundError as e:
print(e)
sys.exit(1)

if cli_args['print_rubrics']:
bazos_scrapper = BazosScrapper(country=country, cli_args=cli_args, user=user)
# bazos_scrapper.check_user_files_available()
bazos_scrapper.load_page_with_cookies()
# bazos_scrapper.check_authentication()
bazos_scrapper.print_all_rubrics_and_categories()
return

bazos_scrapper = BazosScrapper(country=country, cli_args=cli_args, user=user)
bazos_scrapper = BazosScrapper(country=country, args=args, user=bazos_user, driver=bazos_driver.driver)
bazos_scrapper.load_page_with_cookies()

# Restore advertisements
if cli_args['delete_all']:
if args['delete_all']:
bazos_scrapper.delete_advertisements()
if cli_args['create_all']:
if args['create_all']:
bazos_scrapper.create_advertisements()
sys.exit()


if __name__ == '__main__':
from dotenv import load_dotenv

load_dotenv(dotenv_path='.env')
main()
Loading

0 comments on commit 98021e9

Please sign in to comment.