From e04d89a1278f66c15be9cadb6ab524dbb878efd8 Mon Sep 17 00:00:00 2001 From: gabrielgio Date: Sat, 3 Jul 2021 21:24:15 +0200 Subject: Initial commit --- user.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 user.py (limited to 'user.py') diff --git a/user.py b/user.py new file mode 100644 index 0000000..e386c2d --- /dev/null +++ b/user.py @@ -0,0 +1,48 @@ +import praw +from time import sleep + +from nextcloud import NextCloud +from praw.models.util import stream_generator + +from download import Downloader +from util import jsonfy, try_post, parser + +if __name__ == "__main__": + args = parser.parse_args() + reddit = praw.Reddit(client_id=args.client_id, + client_secret=args.client_secret, + password=args.reddit_password, + user_agent="hcrawler", + username=args.reddit_username) + + nxc = NextCloud( + args.nextcloud_host, + user=args.nextcloud_username, + password=args.nextcloud_password, + session_kwargs={'verify': False} + ) + + nxc.create_folder(f"im", True) + + redditor = reddit.redditor(args.reddit_username) + + + def uplaod(post): + url = post.url + nxc.create_folder(f"im/{post.subreddit}/", True) + with Downloader(url=url, reddit=reddit) as d: + d.download() + for path in d.paths: + if "-mobile" in path: # Remove mobile version + continue + nxc.upload_file(path, f"im/{post.subreddit}/{path}") + + + for post in redditor.saved(limit=None): + uplaod(post) + + sleep(60) + + generator = stream_generator(redditor.saved, attribute_name="name") + for post in generator: + uplaod(post) -- cgit v1.2.3