diff options
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -1,4 +1,5 @@ import argparse +import logging import os import praw @@ -35,6 +36,8 @@ parser.add_argument('-d', '--nextcloud-path', help="Nextcloud root folder", default=os.environ.get('NEXTCLOUD_PATH', 'im')) +logging.basicConfig(level=logging.INFO) + if __name__ == "__main__": args = parser.parse_args() reddit = praw.Reddit(client_id=args.client_id, @@ -54,14 +57,20 @@ if __name__ == "__main__": def upload(post): - url = post.url - create_folders(f"{args.nextcloud_path}/{post.subreddit}/", nxc) - with Downloader(url=url, reddit=reddit) as d: - d.download() - for path in d.paths: - if "-mobile" in path: # Remove mobile version - continue - upload_file(path, f"im/{post.subreddit}/{path}", nxc) + try: + url = post.url + create_folders(f"{args.nextcloud_path}/{post.subreddit}/", nxc) + d = Downloader(url=url, reddit=reddit) + with d.provider() as provider: + provider.download() + logging.info(f"{post.id} from {post.subreddit} downloaded") + for path in provider.paths: + if "-mobile" in path: # Remove mobile version + continue + upload_file(path, f"{args.nextcloud_path}/{post.subreddit}/{path}", nxc) + logging.info(f"{path} uploaded") + except Exception as e: + logging.error(e) generator = stream_generator(redditor.saved, attribute_name="name") |