diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5b91d04 --- /dev/null +++ b/Dockerfile @@ -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 [] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a249123 --- /dev/null +++ b/docker-compose.yml @@ -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" diff --git a/save.py b/save.py old mode 100755 new mode 100644 index 7a31a7d..63cde91 --- a/save.py +++ b/save.py @@ -9,10 +9,12 @@ from utilities import * # Get arguments 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("location", type=str, nargs=1, help="The path to save to.") + +if os.getenv("DOCKER", "0") != "1": + parser.add_argument("location", type=str, nargs=1, help="The path to save to.") args = parser.parse_args() 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? if not os.path.isdir(location): diff --git a/utilities.py b/utilities.py index 0ae3a9a..45fb559 100644 --- a/utilities.py +++ b/utilities.py @@ -5,8 +5,15 @@ from redvid import Downloader import youtube_dl import re from datetime import datetime -from secrets import REDDIT_USERNAME, REDDIT_PASSWORD -from secrets import REDDIT_CLIENT_ID, REDDIT_SECRET + +try: + from secrets import REDDIT_USERNAME, REDDIT_PASSWORD + 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"] VIDEO_EXTENSIONS = ["mp4"]