From 9313e27d44abf781deec410304d5f1b74de94cac Mon Sep 17 00:00:00 2001 From: arisnguyenit97 Date: Sun, 24 Mar 2024 10:31:58 +0700 Subject: [PATCH] :wrench: chore: add file try.sh #2 --- Makefile | 4 ++++ main.py | 25 ++++++++++++++++++++----- try.sh | 1 + 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100755 try.sh diff --git a/Makefile b/Makefile index 584f62d..282f4da 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,7 @@ docker-build: docker-compose build docker-up: docker-compose up +local: + python3 main.py ./config/logger.local.yaml ./config/application.local.yaml $(username) +try: + ./try.sh \ No newline at end of file diff --git a/main.py b/main.py index 248d766..abf45cb 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import yaml import os import shutil +import sys class Configs: @@ -69,9 +70,7 @@ def __init__(self, username: str, logger: Logger, config: Configs): self.video_dir = os.path.join( self.root_dir, username, - self.config.get( - "directories.types.video", default="videos", cast_type=str - ), + self.config.get("directories.types.video", default="videos", cast_type=str), ) self.caption_dir = os.path.join( self.root_dir, @@ -134,7 +133,9 @@ def download_posts(self, ctx: instaloader.Profile): self.logger.logger.error("Error downloading posts: %s", e) def execute(self): - enabled: bool = self.config.get("instagram.enabled", cast_type=bool) + enabled: bool = self.config.get( + "instagram.enabled", default=False, cast_type=bool + ) if enabled: username: str = self.config.get("instagram.username", cast_type=str) password: str = self.config.get("instagram.password", cast_type=str) @@ -188,7 +189,7 @@ def main(username, filename_logger, filename_config): scraper.clean_up() -if __name__ == "__main__": +def execute(): if is_docker(): username = os.getenv("INSTAGRAM_USERNAME") else: @@ -196,3 +197,17 @@ def main(username, filename_logger, filename_config): filename_logger = "./config/logger.yaml" filename_config = "./config/application.yaml" main(username, filename_logger, filename_config) + + +def execute_with_args(): + if len(sys.argv) != 4: + print("Usage: python3 main.py ") + sys.exit(1) + filename_logger = sys.argv[1] + filename_config = sys.argv[2] + username = sys.argv[3] + main(username, filename_logger, filename_config) + + +if __name__ == "__main__": + execute_with_args() diff --git a/try.sh b/try.sh new file mode 100755 index 0000000..6c9abea --- /dev/null +++ b/try.sh @@ -0,0 +1 @@ +make local username=phuocnguyenit97