From 45191e2c6043bf0b4913905bcf949e3ecfd347e7 Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 18:40:40 +0300 Subject: [PATCH 01/10] Prompt user if no arguments passed --- script.py | 134 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 119 insertions(+), 15 deletions(-) diff --git a/script.py b/script.py index 4601ba6..816126a 100644 --- a/script.py +++ b/script.py @@ -24,12 +24,6 @@ __version__ = "1.0.1" __maintainer__ = "Ali Parlakci" __email__ = "parlakciali@gmail.com" -def debug(*post): - GLOBAL.config = getConfig('config.json') - GLOBAL.directory = Path(".\\debug\\") - download([*post]) - quit() - def getConfig(configFileName): """Read credentials from config.json file""" @@ -66,7 +60,7 @@ def parseArguments(arguments=[]): description="This program downloads " \ "media from reddit " \ "posts") - parser.add_argument("directory", + parser.add_argument("--directory", help="Specifies the directory where posts will be " \ "downloaded to", metavar="DIRECTORY") @@ -131,7 +125,6 @@ def parseArguments(arguments=[]): parser.add_argument("--limit", help="default: unlimited", metavar="Limit", - default=None, type=int) parser.add_argument("--time", @@ -285,7 +278,8 @@ def prepareAttributes(): ATTRIBUTES["time"] = GLOBAL.arguments.time elif GLOBAL.arguments.subreddit is not None: - GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit) + if type(GLOBAL.arguments.subreddit) == list: + GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit) ATTRIBUTES["subreddit"] = GLOBAL.arguments.subreddit @@ -305,6 +299,116 @@ def prepareAttributes(): return ATTRIBUTES +class PromptUser(): + @staticmethod + def chooseFrom(choices): + print() + choicesByIndex = list(str(x) for x in range(len(choices)+1)) + for i in range(len(choices)): + print("{indent}[{order}] {mode}".format( + indent=" "*4,order=i+1,mode=choices[i] + )) + print(" "*4+"[0] exit\n") + choice = input("> ") + while not choice.lower() in choices+choicesByIndex: + print("Invalid input\n") + programModeIndex = input("> ") + + if choice == "0": + quit() + elif choice in choicesByIndex: + return choices[int(choice)-1] + else: + return choice + + def __init__(self): + print("Select program mode:") + programModes = [ + "search","subreddit","multireddit", + "submitted","upvoted","saved","log" + ] + programMode = self.chooseFrom(programModes) + + if programMode == "search": + GLOBAL.arguments.search = input("\nquery: ") + GLOBAL.arguments.subreddit = input("\nsubreddit: ") + + print("\nSelect sort type:") + sortTypes = [ + "relevance","top","new" + ] + sortType = self.chooseFrom(sortTypes) + GLOBAL.arguments.sort = sortType + + print("\nSelect time filter:") + timeFilters = [ + "hour","day","week","month","year","all" + ] + timeFilter = self.chooseFrom(timeFilters) + GLOBAL.arguments.time = timeFilter + + if programMode == "subreddit": + GLOBAL.arguments.subreddit = input("\nsubreddit: ") + if " " in GLOBAL.arguments.subreddit: + GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit.split()) + + print("\nSelect sort type:") + sortTypes = [ + "hot","top","new","rising","controversial" + ] + sortType = self.chooseFrom(sortTypes) + GLOBAL.arguments.sort = sortType + + if sortType in ["top","controversial"]: + print("\nSelect time filter:") + timeFilters = [ + "hour","day","week","month","year","all" + ] + timeFilter = self.chooseFrom(timeFilters) + GLOBAL.arguments.time = timeFilter + else: + GLOBAL.arguments.time = "all" + + + elif programMode == "multiredit": + GLOBAL.arguments.user = input("\nredditor: ") + GLOBAL.arguments.subreddit = input("\nmultireddit: ") + + print("\nSelect sort type:") + sortTypes = [ + "hot","top","new","rising","controversial" + ] + sortType = self.chooseFrom(sortTypes) + GLOBAL.arguments.sort = sortType + + if sortType in ["top","controversial"]: + print("\nSelect time filter:") + timeFilters = [ + "hour","day","week","month","year","all" + ] + timeFilter = self.chooseFrom(timeFilters) + GLOBAL.arguments.time = timeFilter + else: + GLOBAL.arguments.time = "all" + + + elif programMode == "submitted": + GLOBAL.arguments.submitted = True + GLOBAL.arguments.user = input("\nredditor: ") + + elif programMode == "upvoted": + GLOBAL.arguments.upvoted = True + GLOBAL.arguments.user = input("\nredditor: ") + + elif programMode == "saved": + GLOBAL.arguments.saved = True + GLOBAL.arguments.user = input("\nredditor: ") + + elif programMode == "log": + GLOBAL.arguments.log = input("\nlog file directory:") + + GLOBAL.arguments.limit = int(input("\nlimit: ")) + def postExists(POST): """Figure out a file's name and checks if the file already exists""" @@ -482,15 +586,15 @@ def download(submissions): print(" Total of {} links downloaded!".format(downloadedCount)) def main(): - if sys.argv[-1].endswith(__file__): - GLOBAL.arguments = parseArguments(input("> ").split()) - else: - GLOBAL.arguments = parseArguments() + GLOBAL.arguments = parseArguments() + if GLOBAL.arguments.directory is not None: GLOBAL.directory = Path(GLOBAL.arguments.directory) else: - print("Invalid directory") - quit() + GLOBAL.directory = Path(input("download directory: ")) + + if len(sys.argv) == 1: + PromptUser() GLOBAL.config = getConfig(Path(PurePath(__file__).parent / 'config.json')) checkConflicts() From d9dc3132f693d051e7c0e690ed9f1b76a0234696 Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 18:56:39 +0300 Subject: [PATCH 02/10] Rearranged functions --- script.py | 249 +++++++++++++++++++++++++++--------------------------- 1 file changed, 124 insertions(+), 125 deletions(-) diff --git a/script.py b/script.py index 816126a..24fae28 100644 --- a/script.py +++ b/script.py @@ -210,28 +210,113 @@ def checkConflicts(): print("No redditor name given") quit() -def postFromLog(fileName): - """Analyze a log file and return a list of dictionaries containing - submissions - """ - if Path.is_file(Path(fileName)): - content = jsonFile(fileName).read() - else: - print("File not found") - quit() +class PromptUser(): + @staticmethod + def chooseFrom(choices): + print() + choicesByIndex = list(str(x) for x in range(len(choices)+1)) + for i in range(len(choices)): + print("{indent}[{order}] {mode}".format( + indent=" "*4,order=i+1,mode=choices[i] + )) + print(" "*4+"[0] exit\n") + choice = input("> ") + while not choice.lower() in choices+choicesByIndex: + print("Invalid input\n") + programModeIndex = input("> ") - try: - del content["HEADER"] - except KeyError: - pass + if choice == "0": + quit() + elif choice in choicesByIndex: + return choices[int(choice)-1] + else: + return choice + + def __init__(self): + print("select program mode:") + programModes = [ + "search","subreddit","multireddit", + "submitted","upvoted","saved","log" + ] + programMode = self.chooseFrom(programModes) - posts = [] + if programMode == "search": + GLOBAL.arguments.search = input("\nquery: ") + GLOBAL.arguments.subreddit = input("\nsubreddit: ") - for post in content: - if not content[post][-1]['postType'] == None: - posts.append(content[post][-1]) + print("\nselect sort type:") + sortTypes = [ + "relevance","top","new" + ] + sortType = self.chooseFrom(sortTypes) + GLOBAL.arguments.sort = sortType - return posts + print("\nselect time filter:") + timeFilters = [ + "hour","day","week","month","year","all" + ] + timeFilter = self.chooseFrom(timeFilters) + GLOBAL.arguments.time = timeFilter + + if programMode == "subreddit": + GLOBAL.arguments.subreddit = input("\nsubreddit: ") + if " " in GLOBAL.arguments.subreddit: + GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit.split()) + + print("\nselect sort type:") + sortTypes = [ + "hot","top","new","rising","controversial" + ] + sortType = self.chooseFrom(sortTypes) + GLOBAL.arguments.sort = sortType + + if sortType in ["top","controversial"]: + print("\nselect time filter:") + timeFilters = [ + "hour","day","week","month","year","all" + ] + timeFilter = self.chooseFrom(timeFilters) + GLOBAL.arguments.time = timeFilter + else: + GLOBAL.arguments.time = "all" + + elif programMode == "multiredit": + GLOBAL.arguments.user = input("\nredditor: ") + GLOBAL.arguments.subreddit = input("\nmultireddit: ") + + print("\nselect sort type:") + sortTypes = [ + "hot","top","new","rising","controversial" + ] + sortType = self.chooseFrom(sortTypes) + GLOBAL.arguments.sort = sortType + + if sortType in ["top","controversial"]: + print("\nselect time filter:") + timeFilters = [ + "hour","day","week","month","year","all" + ] + timeFilter = self.chooseFrom(timeFilters) + GLOBAL.arguments.time = timeFilter + else: + GLOBAL.arguments.time = "all" + + elif programMode == "submitted": + GLOBAL.arguments.submitted = True + GLOBAL.arguments.user = input("\nredditor: ") + + elif programMode == "upvoted": + GLOBAL.arguments.upvoted = True + GLOBAL.arguments.user = input("\nredditor: ") + + elif programMode == "saved": + GLOBAL.arguments.saved = True + GLOBAL.arguments.user = input("\nredditor: ") + + elif programMode == "log": + GLOBAL.arguments.log = input("\nlog file directory:") + + GLOBAL.arguments.limit = int(input("\nlimit: ")) def prepareAttributes(): ATTRIBUTES = {} @@ -299,115 +384,28 @@ def prepareAttributes(): return ATTRIBUTES -class PromptUser(): - @staticmethod - def chooseFrom(choices): - print() - choicesByIndex = list(str(x) for x in range(len(choices)+1)) - for i in range(len(choices)): - print("{indent}[{order}] {mode}".format( - indent=" "*4,order=i+1,mode=choices[i] - )) - print(" "*4+"[0] exit\n") - choice = input("> ") - while not choice.lower() in choices+choicesByIndex: - print("Invalid input\n") - programModeIndex = input("> ") +def postFromLog(fileName): + """Analyze a log file and return a list of dictionaries containing + submissions + """ + if Path.is_file(Path(fileName)): + content = jsonFile(fileName).read() + else: + print("File not found") + quit() - if choice == "0": - quit() - elif choice in choicesByIndex: - return choices[int(choice)-1] - else: - return choice - - def __init__(self): - print("Select program mode:") - programModes = [ - "search","subreddit","multireddit", - "submitted","upvoted","saved","log" - ] - programMode = self.chooseFrom(programModes) + try: + del content["HEADER"] + except KeyError: + pass - if programMode == "search": - GLOBAL.arguments.search = input("\nquery: ") - GLOBAL.arguments.subreddit = input("\nsubreddit: ") + posts = [] - print("\nSelect sort type:") - sortTypes = [ - "relevance","top","new" - ] - sortType = self.chooseFrom(sortTypes) - GLOBAL.arguments.sort = sortType + for post in content: + if not content[post][-1]['postType'] == None: + posts.append(content[post][-1]) - print("\nSelect time filter:") - timeFilters = [ - "hour","day","week","month","year","all" - ] - timeFilter = self.chooseFrom(timeFilters) - GLOBAL.arguments.time = timeFilter - - if programMode == "subreddit": - GLOBAL.arguments.subreddit = input("\nsubreddit: ") - if " " in GLOBAL.arguments.subreddit: - GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit.split()) - - print("\nSelect sort type:") - sortTypes = [ - "hot","top","new","rising","controversial" - ] - sortType = self.chooseFrom(sortTypes) - GLOBAL.arguments.sort = sortType - - if sortType in ["top","controversial"]: - print("\nSelect time filter:") - timeFilters = [ - "hour","day","week","month","year","all" - ] - timeFilter = self.chooseFrom(timeFilters) - GLOBAL.arguments.time = timeFilter - else: - GLOBAL.arguments.time = "all" - - - elif programMode == "multiredit": - GLOBAL.arguments.user = input("\nredditor: ") - GLOBAL.arguments.subreddit = input("\nmultireddit: ") - - print("\nSelect sort type:") - sortTypes = [ - "hot","top","new","rising","controversial" - ] - sortType = self.chooseFrom(sortTypes) - GLOBAL.arguments.sort = sortType - - if sortType in ["top","controversial"]: - print("\nSelect time filter:") - timeFilters = [ - "hour","day","week","month","year","all" - ] - timeFilter = self.chooseFrom(timeFilters) - GLOBAL.arguments.time = timeFilter - else: - GLOBAL.arguments.time = "all" - - - elif programMode == "submitted": - GLOBAL.arguments.submitted = True - GLOBAL.arguments.user = input("\nredditor: ") - - elif programMode == "upvoted": - GLOBAL.arguments.upvoted = True - GLOBAL.arguments.user = input("\nredditor: ") - - elif programMode == "saved": - GLOBAL.arguments.saved = True - GLOBAL.arguments.user = input("\nredditor: ") - - elif programMode == "log": - GLOBAL.arguments.log = input("\nlog file directory:") - - GLOBAL.arguments.limit = int(input("\nlimit: ")) + return posts def postExists(POST): """Figure out a file's name and checks if the file already exists""" @@ -595,9 +593,10 @@ def main(): if len(sys.argv) == 1: PromptUser() - GLOBAL.config = getConfig(Path(PurePath(__file__).parent / 'config.json')) + else: + checkConflicts() - checkConflicts() + GLOBAL.config = getConfig(Path(PurePath(__file__).parent / 'config.json')) print(sys.argv) From fd179c0e4b8989ffd9bfcd01250e1abf711c914a Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 18:59:17 +0300 Subject: [PATCH 03/10] Typo fix --- script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script.py b/script.py index 24fae28..3cdd687 100644 --- a/script.py +++ b/script.py @@ -210,7 +210,7 @@ def checkConflicts(): print("No redditor name given") quit() -class PromptUser(): +class PromptUser: @staticmethod def chooseFrom(choices): print() @@ -596,7 +596,7 @@ def main(): else: checkConflicts() - GLOBAL.config = getConfig(Path(PurePath(__file__).parent / 'config.json')) + GLOBAL.config = getConfig("config.json") print(sys.argv) From f6240f402e25334f4d0097df371a944571af4ac2 Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 19:25:24 +0300 Subject: [PATCH 04/10] Refactor checkConflicts() --- script.py | 47 ++++++++--------------------------------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/script.py b/script.py index 3cdd687..8a9a09f 100644 --- a/script.py +++ b/script.py @@ -150,63 +150,32 @@ def checkConflicts(): if not, raise errors """ - if GLOBAL.arguments.saved is False: - saved = 0 - else: - saved = 1 - - if GLOBAL.arguments.subreddit is None: - subreddit = 0 - else: - subreddit = 1 - - if GLOBAL.arguments.submitted is False: - submitted = 0 - else: - submitted = 1 - - if GLOBAL.arguments.search is None: - search = 0 - else: - search = 1 - - if GLOBAL.arguments.log is None: - log = 0 - else: - log = 1 - - if GLOBAL.arguments.link is None: - link = 0 - else: - link = 1 - if GLOBAL.arguments.user is None: user = 0 else: user = 1 - if GLOBAL.arguments.upvoted is False: - upvoted = 0 - else: - upvoted = 1 + modes = ["saved","subreddit","submitted","search","log","link","upvoted"] - if not saved+subreddit+log+link+submitted+upvoted == 1: + values = {x: 0 if x is None or x is False else 1 for x in modes} + + if not sum(values[x] for x in values) == 1: print("Program mode is invalid") quit() - if search+subreddit == 2: + if values["search"]+values["saved"] == 2: print("You cannot search in your saved posts") quit() - if search+submitted == 2: + if values["search"]+values["submitted"] == 2: print("You cannot search in submitted posts") quit() - if search+upvoted == 2: + if values["search"]+values["upvoted"] == 2: print("You cannot search in upvoted posts") quit() - if upvoted+submitted == 1 and user == 0: + if values["upvoted"]+values["submitted"] == 1 and user == 0: print("No redditor name given") quit() From 57a5f0c85cf4dd7111be21801aa07f54f2341833 Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 19:31:32 +0300 Subject: [PATCH 05/10] Print arguments before anything --- script.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script.py b/script.py index 8a9a09f..1f820d7 100644 --- a/script.py +++ b/script.py @@ -560,6 +560,8 @@ def main(): else: GLOBAL.directory = Path(input("download directory: ")) + print(" ".join(sys.argv)) + if len(sys.argv) == 1: PromptUser() else: @@ -567,7 +569,6 @@ def main(): GLOBAL.config = getConfig("config.json") - print(sys.argv) if GLOBAL.arguments.log is not None: logDir = Path(GLOBAL.arguments.log) From 65592c5d3a9c2e6812668707b333f490cd42c916 Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 19:57:38 +0300 Subject: [PATCH 06/10] Improved checkConflicts() --- script.py | 25 +++++++++++-------------- src/errors.py | 9 +++++++++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/script.py b/script.py index 1f820d7..3db5807 100644 --- a/script.py +++ b/script.py @@ -160,24 +160,19 @@ def checkConflicts(): values = {x: 0 if x is None or x is False else 1 for x in modes} if not sum(values[x] for x in values) == 1: - print("Program mode is invalid") - quit() + raise ProgramModeError("Invalid program mode") if values["search"]+values["saved"] == 2: - print("You cannot search in your saved posts") - quit() + raise SearchModeError("You cannot search in your saved posts") if values["search"]+values["submitted"] == 2: - print("You cannot search in submitted posts") - quit() + raise SearchModeError("You cannot search in submitted posts") if values["search"]+values["upvoted"] == 2: - print("You cannot search in upvoted posts") - quit() + raise SearchModeError("You cannot search in upvoted posts") if values["upvoted"]+values["submitted"] == 1 and user == 0: - print("No redditor name given") - quit() + raise RedditorNameError("No redditor name given") class PromptUser: @staticmethod @@ -280,7 +275,6 @@ class PromptUser: elif programMode == "saved": GLOBAL.arguments.saved = True - GLOBAL.arguments.user = input("\nredditor: ") elif programMode == "log": GLOBAL.arguments.log = input("\nlog file directory:") @@ -562,10 +556,13 @@ def main(): print(" ".join(sys.argv)) - if len(sys.argv) == 1: - PromptUser() - else: + try: checkConflicts() + except ProgramModeError as err: + PromptUser() + except Exception as err: + print(err) + quit() GLOBAL.config = getConfig("config.json") diff --git a/src/errors.py b/src/errors.py index 8ebc185..4446ad2 100644 --- a/src/errors.py +++ b/src/errors.py @@ -19,6 +19,15 @@ class FileNameTooLong(Exception): class InvalidRedditLink(Exception): pass +class ProgramModeError(Exception): + pass + +class SearchModeError(Exception): + pass + +class RedditorNameError(Exception): + pass + class NoMatchingSubmissionFound(Exception): pass From 7f97bd212a23d7c59fb276db55698c2041f4b770 Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 21:25:45 +0300 Subject: [PATCH 07/10] Bug fix --- script.py | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/script.py b/script.py index 3db5807..ec44cdc 100644 --- a/script.py +++ b/script.py @@ -205,8 +205,8 @@ class PromptUser: programMode = self.chooseFrom(programModes) if programMode == "search": - GLOBAL.arguments.search = input("\nquery: ") - GLOBAL.arguments.subreddit = input("\nsubreddit: ") + GLOBAL.arguments.search = input("query: ") + GLOBAL.arguments.subreddit = input("subreddit: ") print("\nselect sort type:") sortTypes = [ @@ -223,7 +223,7 @@ class PromptUser: GLOBAL.arguments.time = timeFilter if programMode == "subreddit": - GLOBAL.arguments.subreddit = input("\nsubreddit: ") + GLOBAL.arguments.subreddit = input("subreddit: ") if " " in GLOBAL.arguments.subreddit: GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit.split()) @@ -244,9 +244,9 @@ class PromptUser: else: GLOBAL.arguments.time = "all" - elif programMode == "multiredit": - GLOBAL.arguments.user = input("\nredditor: ") - GLOBAL.arguments.subreddit = input("\nmultireddit: ") + elif programMode == "multireddit": + GLOBAL.arguments.user = input("redditor: ") + GLOBAL.arguments.subreddit = input("multireddit: ") print("\nselect sort type:") sortTypes = [ @@ -267,19 +267,44 @@ class PromptUser: elif programMode == "submitted": GLOBAL.arguments.submitted = True - GLOBAL.arguments.user = input("\nredditor: ") + GLOBAL.arguments.user = input("redditor: ") + + print("\nselect sort type:") + sortTypes = [ + "hot","top","new","controversial" + ] + sortType = self.chooseFrom(sortTypes) + GLOBAL.arguments.sort = sortType + + if sortType == "top": + print("\nselect time filter:") + timeFilters = [ + "hour","day","week","month","year","all" + ] + timeFilter = self.chooseFrom(timeFilters) + GLOBAL.arguments.time = timeFilter + else: + GLOBAL.arguments.time = "all" elif programMode == "upvoted": GLOBAL.arguments.upvoted = True - GLOBAL.arguments.user = input("\nredditor: ") + GLOBAL.arguments.user = input("redditor: ") elif programMode == "saved": GLOBAL.arguments.saved = True elif programMode == "log": - GLOBAL.arguments.log = input("\nlog file directory:") + while True: + GLOBAL.arguments.log = input("log file directory:") + if Path(GLOBAL.arguments.log ).is_file(): + break - GLOBAL.arguments.limit = int(input("\nlimit: ")) + while True: + try: + GLOBAL.arguments.limit = int(input("limit: ")) + break + except ValueError: + pass def prepareAttributes(): ATTRIBUTES = {} @@ -554,7 +579,7 @@ def main(): else: GLOBAL.directory = Path(input("download directory: ")) - print(" ".join(sys.argv)) + print("\n"," ".join(sys.argv),"\n") try: checkConflicts() From d080ca17bcd71ab26a26cc88e112b36be93927a7 Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 21:58:26 +0300 Subject: [PATCH 08/10] Changes for latest update on the code --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dd11ae5..82cced6 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ It should redirect to a page which shows your **imgur_client_id** and **imgur_cl \*Select **OAuth 2 authorization without a callback URL** first then select **Anonymous usage without user authorization** if it says *Authorization callback URL: required* ## Program Modes -All the program modes are activated with command-line arguments as shown [here](#using-the-command-line-arguments) - **saved mode** - Gets posts from given user's saved posts. - **submitted mode** @@ -60,19 +59,18 @@ All the program modes are activated with command-line arguments as shown [here]( - Gets posts from given user's upvoted posts. - **subreddit mode** - Gets posts from given subreddit or subreddits that is sorted by given type and limited by given number. - - You may also use search in this mode. See [`python script.py --help`](#using-the-command-line-arguments). - **multireddit mode** - Gets posts from given user's given multireddit that is sorted by given type and limited by given number. - **link mode** - Gets posts from given reddit link. - You may customize the behaviour with `--sort`, `--time`, `--limit`. - - You may also use search in this mode. See [`python script.py --help`](#using-the-command-line-arguments). + - This mode is only accessible via command-line arguments. See **[`python script.py --help`](#using-the-command-line-arguments)** - **log read mode** - Takes a log file which created by itself (json files), reads posts and tries downloading them again. - Running log read mode for FAILED.json file once after the download is complete is **HIGHLY** recommended as unexpected problems may occur. ## Running the script -**DO NOT** let more than one instance of the script run as it interferes with IMGUR Request Rate. +Letting more than one instance of the script run is **not** suggested as it interferes with IMGUR Request Rate. ### Using the command line arguments If no arguments are passed program will prompt you for arguments below which means you may start up the script with double-clicking on it (at least on Windows for sure). @@ -170,6 +168,8 @@ Python have real issues about naming their program - Self posts are held at reddit as styled with markdown. So, the script downloads them as they are in order not to lose their stylings. However, there is a great Chrome extension [here](https://chrome.google.com/webstore/detail/markdown-viewer/ckkdlimhmcjmikdlpkmbgfkaikojcbjk) for viewing Markdown files with its styling. Install it and open the files with Chrome. ## Changelog +### [11/07/2018]() +- Improve UX and UI ### [10/07/2018](https://github.com/aliparlakci/bulk-downloader-for-reddit/tree/ffe3839aee6dc1a552d95154d817aefc2b66af81) - Added support for *self* post - Now getting posts is quicker From 3b15141b49ce74a3fbed026a0534cf7b6162dc0b Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 22:18:54 +0300 Subject: [PATCH 09/10] Bug fix --- script.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script.py b/script.py index ec44cdc..c16f3f2 100644 --- a/script.py +++ b/script.py @@ -157,7 +157,12 @@ def checkConflicts(): modes = ["saved","subreddit","submitted","search","log","link","upvoted"] - values = {x: 0 if x is None or x is False else 1 for x in modes} + values = { + x: 0 if getattr(GLOBAL.arguments,x) is None or \ + getattr(GLOBAL.arguments,x) is False \ + else 1 \ + for x in modes + } if not sum(values[x] for x in values) == 1: raise ProgramModeError("Invalid program mode") From cae044f7b66ab7a2416e1772f40eed207e46c4d2 Mon Sep 17 00:00:00 2001 From: Ali Parlakci Date: Wed, 11 Jul 2018 23:27:16 +0300 Subject: [PATCH 10/10] Stylize print outs --- script.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/script.py b/script.py index c16f3f2..52f7c3f 100644 --- a/script.py +++ b/script.py @@ -210,8 +210,8 @@ class PromptUser: programMode = self.chooseFrom(programModes) if programMode == "search": - GLOBAL.arguments.search = input("query: ") - GLOBAL.arguments.subreddit = input("subreddit: ") + GLOBAL.arguments.search = input("\nquery: ") + GLOBAL.arguments.subreddit = input("\nsubreddit: ") print("\nselect sort type:") sortTypes = [ @@ -228,7 +228,7 @@ class PromptUser: GLOBAL.arguments.time = timeFilter if programMode == "subreddit": - GLOBAL.arguments.subreddit = input("subreddit: ") + GLOBAL.arguments.subreddit = input("\nsubreddit: ") if " " in GLOBAL.arguments.subreddit: GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit.split()) @@ -250,8 +250,8 @@ class PromptUser: GLOBAL.arguments.time = "all" elif programMode == "multireddit": - GLOBAL.arguments.user = input("redditor: ") - GLOBAL.arguments.subreddit = input("multireddit: ") + GLOBAL.arguments.user = input("\nredditor: ") + GLOBAL.arguments.subreddit = input("\nmultireddit: ") print("\nselect sort type:") sortTypes = [ @@ -272,7 +272,7 @@ class PromptUser: elif programMode == "submitted": GLOBAL.arguments.submitted = True - GLOBAL.arguments.user = input("redditor: ") + GLOBAL.arguments.user = input("\nredditor: ") print("\nselect sort type:") sortTypes = [ @@ -293,20 +293,20 @@ class PromptUser: elif programMode == "upvoted": GLOBAL.arguments.upvoted = True - GLOBAL.arguments.user = input("redditor: ") + GLOBAL.arguments.user = input("\nredditor: ") elif programMode == "saved": GLOBAL.arguments.saved = True elif programMode == "log": while True: - GLOBAL.arguments.log = input("log file directory:") + GLOBAL.arguments.log = input("\nlog file directory:") if Path(GLOBAL.arguments.log ).is_file(): break while True: try: - GLOBAL.arguments.limit = int(input("limit: ")) + GLOBAL.arguments.limit = int(input("\nlimit: ")) break except ValueError: pass