aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/main.py b/main.py
index 72c10fd..036aab3 100644
--- a/main.py
+++ b/main.py
@@ -1,6 +1,7 @@
import argparse
import logging
import os
+from time import sleep
import praw
@@ -10,6 +11,15 @@ from praw.models.util import stream_generator
from importer.downloader import Downloader
from importer.uploader import upload_file, create_folders
+levels = {
+ 'critical': logging.CRITICAL,
+ 'error': logging.ERROR,
+ 'warn': logging.WARNING,
+ 'warning': logging.WARNING,
+ 'info': logging.INFO,
+ 'debug': logging.DEBUG
+}
+
parser = argparse.ArgumentParser(description="Monitor saved")
parser.add_argument('-c', '--client-id',
help="Reddit client id",
@@ -35,11 +45,22 @@ parser.add_argument('-o', '--nextcloud-host',
parser.add_argument('-d', '--nextcloud-path',
help="Nextcloud root folder",
default=os.environ.get('NEXTCLOUD_PATH', 'im'))
-
-logging.basicConfig(level=logging.INFO)
+parser.add_argument('-f', '--from-beginning',
+ dest='from_beginning',
+ help="it will attempt to download all saved posts from the beginning.",
+ action='store_true',
+ default=os.environ.get("FROM_BEGINNING") is not None)
+parser.add_argument('-l', '--log-level',
+ default=os.environ.get('LOG_LEVEL', 'info'),
+ choices=levels.keys(),
+ help=f'it will set log level.')
if __name__ == "__main__":
args = parser.parse_args()
+
+ level = levels.get(args.log_level.lower())
+ logging.basicConfig(level=level)
+
reddit = praw.Reddit(client_id=args.client_id,
client_secret=args.client_secret,
password=args.reddit_password,
@@ -73,6 +94,12 @@ if __name__ == "__main__":
logging.error(e)
+ if args.from_beginning:
+ logging.info(f"Downloading from the beginning")
+ for post in redditor.saved(limit=None):
+ upload(post)
+ sleep(60)
+
generator = stream_generator(redditor.saved, attribute_name="name")
for post in generator:
upload(post)