diff options
author | gabrielgio <gabriel.giovanini@pm.me> | 2021-07-26 22:28:05 +0200 |
---|---|---|
committer | gabrielgio <gabriel.giovanini@pm.me> | 2021-07-26 22:36:04 +0200 |
commit | c8bd60648d193f85479d5f380b05bb6d4394ffda (patch) | |
tree | bf28d510da708ce45c39a6e3accdc514a6b2cd1c /main.py | |
parent | bf0cde0b0bb77cd75db03327a461abf26b90c465 (diff) | |
download | reddit-nextcloud-importer-c8bd60648d193f85479d5f380b05bb6d4394ffda.tar.gz reddit-nextcloud-importer-c8bd60648d193f85479d5f380b05bb6d4394ffda.tar.bz2 reddit-nextcloud-importer-c8bd60648d193f85479d5f380b05bb6d4394ffda.zip |
fix: Various fixes
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") |