Merge pull request #2 from TheBritishAccent/master

Add docker support
This commit is contained in:
Sam Ireland 2021-01-28 20:33:05 +00:00 committed by GitHub
commit d8c3feb6ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 4 deletions

25
Dockerfile Normal file
View File

@ -0,0 +1,25 @@
FROM jrottenberg/ffmpeg:4.0-alpine
ENV PYTHONUNBUFFERED=1
ENV DOCKER=1
RUN apk add build-base && apk add python3-dev
RUN echo "**** install Python ****" && \
apk add --no-cache python3 && \
if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi && \
\
echo "**** install pip ****" && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --no-cache --upgrade pip setuptools wheel && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi
COPY requirements.txt /opt/app/requirements.txt
WORKDIR /opt/app
RUN pip install -r requirements.txt
COPY . .
ENTRYPOINT ["python", "save.py"]
CMD []

12
docker-compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: "3.2"
services:
reddit-save:
build: .
image: reddit-save:latest
environment:
REDDIT_USERNAME:
REDDIT_PASSWORD:
REDDIT_CLIENT_ID:
REDDIT_SECRET:
volumes:
- "./archive:/opt/app/archive"

4
save.py Executable file → Normal file
View File

@ -9,10 +9,12 @@ from utilities import *
# Get arguments # Get arguments
parser = argparse.ArgumentParser(description="Save reddit posts to file.") parser = argparse.ArgumentParser(description="Save reddit posts to file.")
parser.add_argument("mode", type=str, nargs=1, choices=["saved", "upvoted"], help="The file to convert.") parser.add_argument("mode", type=str, nargs=1, choices=["saved", "upvoted"], help="The file to convert.")
if os.getenv("DOCKER", "0") != "1":
parser.add_argument("location", type=str, nargs=1, help="The path to save to.") parser.add_argument("location", type=str, nargs=1, help="The path to save to.")
args = parser.parse_args() args = parser.parse_args()
mode = args.mode[0] mode = args.mode[0]
location = args.location[0] location = "./archive/" if os.getenv("DOCKER", "0") == "1" else args.location[0]
# Is location specified a directory? # Is location specified a directory?
if not os.path.isdir(location): if not os.path.isdir(location):

View File

@ -5,8 +5,15 @@ from redvid import Downloader
import youtube_dl import youtube_dl
import re import re
from datetime import datetime from datetime import datetime
try:
from secrets import REDDIT_USERNAME, REDDIT_PASSWORD from secrets import REDDIT_USERNAME, REDDIT_PASSWORD
from secrets import REDDIT_CLIENT_ID, REDDIT_SECRET from secrets import REDDIT_CLIENT_ID, REDDIT_SECRET
except ImportError:
REDDIT_USERNAME = os.getenv("REDDIT_USERNAME")
REDDIT_PASSWORD = os.getenv("REDDIT_PASSWORD")
REDDIT_CLIENT_ID = os.getenv("REDDIT_CLIENT_ID")
REDDIT_SECRET = os.getenv("REDDIT_SECRET")
IMAGE_EXTENSIONS = ["gif", "gifv", "jpg", "jpeg", "png"] IMAGE_EXTENSIONS = ["gif", "gifv", "jpg", "jpeg", "png"]
VIDEO_EXTENSIONS = ["mp4"] VIDEO_EXTENSIONS = ["mp4"]