Skip to content

Commit

Permalink
🔧 chore: add file try.sh #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Mar 24, 2024
1 parent 93f2fbd commit 9313e27
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 20 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import yaml
import os
import shutil
import sys


class Configs:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -188,11 +189,25 @@ def main(username, filename_logger, filename_config):
scraper.clean_up()


if __name__ == "__main__":
def execute():
if is_docker():
username = os.getenv("INSTAGRAM_USERNAME")
else:
username = input("Enter Instagram's username: ")
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 <filename_logger> <filename_config> <username>")
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()
1 change: 1 addition & 0 deletions try.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make local username=phuocnguyenit97

0 comments on commit 9313e27

Please sign in to comment.