From 593094d14b075eec523382154a84f25c043237e1 Mon Sep 17 00:00:00 2001 From: andronedev Date: Thu, 2 Jun 2022 21:49:38 +0200 Subject: [PATCH 1/3] add Docker support --- .dockerignore | 1 + .gitignore | 4 +++- Dockerfile | 14 ++++++++++++++ build.sh | 1 + run.sh | 1 + video_creation/screenshot_downloader.py | 7 ++++--- 6 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 build.sh create mode 100755 run.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1d1fe94 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile \ No newline at end of file diff --git a/.gitignore b/.gitignore index a4589e5..52b1988 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ assets/ .env -reddit-bot-351418-5560ebc49cac.json \ No newline at end of file +reddit-bot-351418-5560ebc49cac.json +__pycache__ +out \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9d7f280 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM mcr.microsoft.com/playwright + +RUN apt update +RUN apt install python3-pip -y + +RUN mkdir /app +ADD . /app +WORKDIR /app +RUN pip install -r requirements.txt + +# tricks for pytube : https://github.com/elebumm/RedditVideoMakerBot/issues/142 +RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py + +CMD ["python3", "main.py"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7d4dfc6 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +docker build -t rvmt . \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..f2a150f --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +docker run -v $(pwd)/out/:/app/assets -it rvmt \ No newline at end of file diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 66c96f1..e5a5dbf 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -1,4 +1,4 @@ -from playwright.sync_api import sync_playwright +from playwright.sync_api import sync_playwright, ViewportSize from pathlib import Path from rich.progress import track from utils.console import print_step, print_substep @@ -24,7 +24,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): # Get the thread screenshot page = browser.new_page() page.goto(reddit_object["thread_url"]) - + page.set_viewport_size(ViewportSize(width=1920, height=1080)) if page.locator('[data-testid="content-gate"]').is_visible(): # This means the post is NSFW and requires to click the proceed button. @@ -50,4 +50,5 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): page.locator(f"#t1_{comment['comment_id']}").screenshot( path=f"assets/png/comment_{idx}.png" ) - print_substep("Screenshots downloaded Successfully.", style="bold green") + print_substep("Screenshots downloaded Successfully.", + style="bold green") From 49de46dd539c1d75f77691fa348b0c85cf66862c Mon Sep 17 00:00:00 2001 From: andronedev <31452517+andronedev@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:14:17 +0200 Subject: [PATCH 2/3] Update Dockerfile --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9d7f280..1f68ea0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ WORKDIR /app RUN pip install -r requirements.txt # tricks for pytube : https://github.com/elebumm/RedditVideoMakerBot/issues/142 -RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py +# (NOTE : This is no longer useful since pytube was removed from the dependencies) +# RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py -CMD ["python3", "main.py"] \ No newline at end of file +CMD ["python3", "main.py"] From 030c7706c69905952fbc0e382a312c35e2c85f41 Mon Sep 17 00:00:00 2001 From: andronedev Date: Thu, 2 Jun 2022 22:56:32 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8feature:=20possibility=20to=20use?= =?UTF-8?q?=20an=20external=20.env=20instead=20of=20having=20to=20build=20?= =?UTF-8?q?the=20container=20for=20each=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index f2a150f..4dcb69a 100755 --- a/run.sh +++ b/run.sh @@ -1 +1 @@ -docker run -v $(pwd)/out/:/app/assets -it rvmt \ No newline at end of file +docker run -v $(pwd)/out/:/app/assets -v $(pwd)/.env:/app/.env -it rvmt \ No newline at end of file