1
0
Fork 0
mirror of synced 2024-06-22 16:10:36 +12:00

Add --config option for explicitly stating configuration file to use.

aliparlakci/bulk-downloader-for-reddit#122

Address comments in pull review.

* Removed vertical space.
* Added config file existence check with log message.
This commit is contained in:
Robert Pufky 2020-06-07 13:01:26 -07:00
parent 2ba763e03b
commit 37a3d83725
3 changed files with 34 additions and 13 deletions

View file

@ -180,7 +180,15 @@ Example usage: **`--no-download`**
Takes a file directory as a parameter and skips the posts if it matches with the post IDs inside the file. It also saves the newly downloaded posts to the given file.
Example usage: **`--downloaded-posts D:\bdfr\ALL_POSTS.txt`**
## **`--config`**
Specify a `config.json` file to use. This will disable reading from the default `Bulk downloader for reddit/config.json` file, as well as `--use-local-config` option.
Example usage: **`--config /etc/bdfr/config.json`**
Example usage: **`-c ~/config.json`**
Example usage: **`--config c:\Users\Me\Downloads\config.json`**
Example usage: **`-c c:\config.json`**
## ❔ FAQ
### I am running the script on a headless machine or on a remote server. How can I authenticate my reddit account?

View file

@ -256,14 +256,24 @@ def printLogo():
)
def main():
arguments = Arguments.parse()
GLOBAL.arguments = arguments
if not Path(GLOBAL.defaultConfigDirectory).is_dir():
os.makedirs(GLOBAL.defaultConfigDirectory)
if Path("config.json").exists():
GLOBAL.configDirectory = Path("config.json")
if arguments.config:
if arguments.use_local_config:
sys.exit()
if Path(arguments.config).exists():
GLOBAL.configDirectory = Path(arguments.config)
else:
VanillaPrint("custom config",arguments.config,"not found. Exiting.")
sys.exit()
else:
GLOBAL.configDirectory = GLOBAL.defaultConfigDirectory / "config.json"
if not Path(GLOBAL.defaultConfigDirectory).is_dir():
os.makedirs(GLOBAL.defaultConfigDirectory)
if Path("config.json").exists():
GLOBAL.configDirectory = Path("config.json")
else:
GLOBAL.configDirectory = GLOBAL.defaultConfigDirectory / "config.json"
try:
GLOBAL.config = Config(GLOBAL.configDirectory).generate()
except InvalidJSONFile as exception:
@ -274,9 +284,6 @@ def main():
sys.argv = sys.argv + GLOBAL.config["options"].split()
arguments = Arguments.parse()
GLOBAL.arguments = arguments
if arguments.set_filename:
Config(GLOBAL.configDirectory).setCustomFileName()
sys.exit()
@ -362,4 +369,4 @@ if __name__ == "__main__":
print(GLOBAL.log_stream.getvalue())
if not GLOBAL.arguments.quit: input("\nPress enter to quit\n")

View file

@ -153,9 +153,15 @@ class Arguments:
action="store_true",
help="Just saved posts into a the POSTS.json file without downloading"
)
parser.add_argument("--config","-c",
help="Specify exact config.json file to use. " \
"Disables reading from 'Bulk downloader for " \
"reddit/config.json' and --use-local-config " \
"option."
)
if arguments == []:
return parser.parse_args()
else:
return parser.parse_args(arguments)
return parser.parse_args(arguments)