aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/main.py b/main.py
index 575a7ef..72c10fd 100644
--- a/main.py
+++ b/main.py
@@ -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")