diff options
author | gabrielgio <gabriel.giovanini@pm.me> | 2021-07-27 21:39:27 +0200 |
---|---|---|
committer | gabrielgio <gabriel.giovanini@pm.me> | 2021-07-27 21:39:27 +0200 |
commit | 3d54b3d91d0c175feae82c413fd0139545d46e2a (patch) | |
tree | 8d57175d1c364c2be3800818cd682e01b748089e /main.py | |
parent | c8bd60648d193f85479d5f380b05bb6d4394ffda (diff) | |
download | reddit-nextcloud-importer-3d54b3d91d0c175feae82c413fd0139545d46e2a.tar.gz reddit-nextcloud-importer-3d54b3d91d0c175feae82c413fd0139545d46e2a.tar.bz2 reddit-nextcloud-importer-3d54b3d91d0c175feae82c413fd0139545d46e2a.zip |
feat: Add two more options
* from beginning: it will download all available saved posts.
* log level: it will set a log level to logging lib.
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -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) |