From 68a643ebec6f702f38706c83ffe43dc96456ba68 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 7 Jul 2022 00:15:01 -0400 Subject: [PATCH 1/6] Update lint.yml --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a8fbb93..0ca5c5d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,7 +23,7 @@ jobs: run: | black . --line-length 101 git config --global user.name 'autoblack' - git config --global user.email 'JasonLovesDoggo@users.noreply.github.com' + git config --global user.email 'jasoncameron.all@gmail.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY git checkout $GITHUB_HEAD_REF git commit -am "fixup: Format Python code with Black" From 40bfcf468e63cc6a2da0f73a59fb6c5f5588ca70 Mon Sep 17 00:00:00 2001 From: autoblack Date: Thu, 7 Jul 2022 04:38:26 +0000 Subject: [PATCH 2/6] fixup: Format Python code with Black --- utils/settings.py | 35 ++++++++--------------------------- video_creation/final_video.py | 12 ++++++------ 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/utils/settings.py b/utils/settings.py index 7c2b05d..a36f63e 100755 --- a/utils/settings.py +++ b/utils/settings.py @@ -11,8 +11,9 @@ from utils.console import handle_input console = Console() config = dict # autocomplete + def crawl(obj: dict, func=lambda x, y: print(x, y, end="\n"), path=None): - if path is None: # path Default argument value is mutable + if path is None: # path Default argument value is mutable path = [] for key in obj.keys(): if type(obj[key]) is dict: @@ -53,11 +54,7 @@ def check(value, checks, name): and not hasattr(value, "__iter__") and ( ("nmin" in checks and checks["nmin"] is not None and value < checks["nmin"]) - or ( - "nmax" in checks - and checks["nmax"] is not None - and value > checks["nmax"] - ) + or ("nmax" in checks and checks["nmax"] is not None and value > checks["nmax"]) ) ): incorrect = True @@ -65,16 +62,8 @@ def check(value, checks, name): not incorrect and hasattr(value, "__iter__") and ( - ( - "nmin" in checks - and checks["nmin"] is not None - and len(value) < checks["nmin"] - ) - or ( - "nmax" in checks - and checks["nmax"] is not None - and len(value) > checks["nmax"] - ) + ("nmin" in checks and checks["nmin"] is not None and len(value) < checks["nmin"]) + or ("nmax" in checks and checks["nmax"] is not None and len(value) > checks["nmax"]) ) ): incorrect = True @@ -82,15 +71,9 @@ def check(value, checks, name): if incorrect: value = handle_input( message=( - ( - ("[blue]Example: " + str(checks["example"]) + "\n") - if "example" in checks - else "" - ) + (("[blue]Example: " + str(checks["example"]) + "\n") if "example" in checks else "") + "[red]" - + ("Non-optional ", "Optional ")[ - "optional" in checks and checks["optional"] is True - ] + + ("Non-optional ", "Optional ")["optional" in checks and checks["optional"] is True] ) + "[#C0CAF5 bold]" + str(name) @@ -131,9 +114,7 @@ def check_toml(template_file, config_file) -> Tuple[bool, Dict]: try: template = toml.load(template_file) except Exception as error: - console.print( - f"[red bold]Encountered error when trying to to load {template_file}: {error}" - ) + console.print(f"[red bold]Encountered error when trying to to load {template_file}: {error}") return False try: config = toml.load(config_file) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index ebdf4d0..d08e4cb 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -46,7 +46,10 @@ def name_normalize(name: str) -> str: else: return name -def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, background_config: Tuple[str, str, str, Any]): + +def make_final_video( + number_of_clips: int, length: int, reddit_obj: dict, background_config: Tuple[str, str, str, Any] +): """Gathers audio clips, gathers all screenshots, stitches them together and saves the final video to assets/temp Args: number_of_clips (int): Index to end at when going through the screenshots' @@ -66,9 +69,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr ) # Gather all audio clips - audio_clips = [ - AudioFileClip(f"assets/temp/mp3/{i}.mp3") for i in range(number_of_clips) - ] + audio_clips = [AudioFileClip(f"assets/temp/mp3/{i}.mp3") for i in range(number_of_clips)] audio_clips.insert(0, AudioFileClip("assets/temp/mp3/title.mp3")) audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) @@ -105,8 +106,7 @@ def make_final_video(number_of_clips: int, length: int, reddit_obj: dict, backgr # ) # else: story mode stuff img_clip_pos = background_config[3] - image_concat = concatenate_videoclips( - image_clips).set_position(img_clip_pos) + image_concat = concatenate_videoclips(image_clips).set_position(img_clip_pos) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) title = re.sub(r"[^\w\s-]", "", reddit_obj["thread_title"]) From 532e49276a7331e0db78636109e62f349ec01d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Mustafa=20Ak=C5=9Fam?= Date: Thu, 7 Jul 2022 14:36:23 +0300 Subject: [PATCH 3/6] Adding subreddit to videos.json Adding subreddit data to videos.json --- utils/videos.py | 4 +++- video_creation/final_video.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/videos.py b/utils/videos.py index d050ab8..4a91e8c 100755 --- a/utils/videos.py +++ b/utils/videos.py @@ -34,11 +34,12 @@ def check_done( return redditobj -def save_data(filename: str, reddit_title: str, reddit_id: str, credit: str): +def save_data(subreddit: str, filename: str, reddit_title: str, reddit_id: str, credit: str): """Saves the videos that have already been generated to a JSON file in video_creation/data/videos.json Args: filename (str): The finished video title name + @param subreddit: @param filename: @param reddit_id: @param reddit_title: @@ -48,6 +49,7 @@ def save_data(filename: str, reddit_title: str, reddit_id: str, credit: str): if reddit_id in [video["id"] for video in done_vids]: return # video already done but was specified to continue anyway in the config file payload = { + "subreddit": subreddit, "id": reddit_id, "time": str(int(time.time())), "background_credit": credit, diff --git a/video_creation/final_video.py b/video_creation/final_video.py index d08e4cb..1dad789 100755 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -115,7 +115,7 @@ def make_final_video( filename = f"{name_normalize(title)}.mp4" subreddit = settings.config["reddit"]["thread"]["subreddit"] - save_data(filename, title, idx, background_config[2]) + save_data(subreddit, filename, title, idx, background_config[2]) if not exists(f"./results/{subreddit}"): print_substep("The results folder didn't exist so I made it") From b51ba9a002dd7fdfbbd3a58862f9168921e61438 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Thu, 7 Jul 2022 22:43:30 +0100 Subject: [PATCH 4/6] chore: lint on pr, lint+fix on push to master --- .github/workflows/autoblack.yml | 32 ++++++++++++++++++++++++++++++++ .github/workflows/lint.yml | 32 ++++++-------------------------- 2 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/autoblack.yml diff --git a/.github/workflows/autoblack.yml b/.github/workflows/autoblack.yml new file mode 100644 index 0000000..ba9cc36 --- /dev/null +++ b/.github/workflows/autoblack.yml @@ -0,0 +1,32 @@ +# GitHub Action that uses Black to reformat the Python code in an incoming pull request. +# If all Python code in the pull request is compliant with Black then this Action does nothing. +# Othewrwise, Black is run and its changes are committed back to the incoming pull request. +# https://github.com/cclauss/autoblack + +name: autoblack +on: + push: + branches: ["master"] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.9 + - name: Install Black + run: pip install black + - name: Run black --check . + run: black --check . + - name: If needed, commit black changes to the pull request + if: failure() + run: | + black . --line-length 101 + git config --global user.name 'autoblack' + git config --global user.email 'jasoncameron.all@gmail.com' + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git checkout $GITHUB_HEAD_REF + git commit -am "fixup: Format Python code with Black" + git push diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0ca5c5d..75ad759 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,30 +1,10 @@ -# GitHub Action that uses Black to reformat the Python code in an incoming pull request. -# If all Python code in the pull request is compliant with Black then this Action does nothing. -# Othewrwise, Black is run and its changes are committed back to the incoming pull request. -# https://github.com/cclauss/autoblack +name: Lint + +on: [pull_request] -name: autoblack -on: [pull_request, workflow_dispatch] jobs: - build: + lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.9 - - name: Install Black - run: pip install black - - name: Run black --check . - run: black --check . - - name: If needed, commit black changes to the pull request - if: failure() - run: | - black . --line-length 101 - git config --global user.name 'autoblack' - git config --global user.email 'jasoncameron.all@gmail.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - git checkout $GITHUB_HEAD_REF - git commit -am "fixup: Format Python code with Black" - git push + - uses: actions/checkout@v2 + - uses: psf/black@stable From d6be83ef80fec7e9ecb771c05b8c76ae6771231a Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Thu, 7 Jul 2022 21:52:45 +0000 Subject: [PATCH 5/6] fix: match lint line length to autoblack --- .github/workflows/lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 75ad759..f95531f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,3 +8,5 @@ jobs: steps: - uses: actions/checkout@v2 - uses: psf/black@stable + with: + options: "--line-length 101" From e6169ee905464d5b4a2cf1ec74db0e9fea189133 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Fri, 8 Jul 2022 02:18:08 +0100 Subject: [PATCH 6/6] fix: skip posts with no comments --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 8365d04..b64a52a 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -72,7 +72,7 @@ def get_subreddit_threads(POST_ID: str): threads = subreddit.hot(limit=25) submission = get_subreddit_undone(threads, subreddit) submission = check_done(submission) # double-checking - if submission is None: + if submission is None or not submission.num_comments: return get_subreddit_threads(POST_ID) # submission already done. rerun upvotes = submission.score ratio = submission.upvote_ratio * 100