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:
parent
2ba763e03b
commit
37a3d83725
10
README.md
10
README.md
|
@ -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.
|
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`**
|
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
|
## ❔ FAQ
|
||||||
|
|
||||||
### I am running the script on a headless machine or on a remote server. How can I authenticate my reddit account?
|
### I am running the script on a headless machine or on a remote server. How can I authenticate my reddit account?
|
||||||
|
|
27
script.py
27
script.py
|
@ -256,14 +256,24 @@ def printLogo():
|
||||||
)
|
)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
arguments = Arguments.parse()
|
||||||
|
GLOBAL.arguments = arguments
|
||||||
|
|
||||||
if not Path(GLOBAL.defaultConfigDirectory).is_dir():
|
if arguments.config:
|
||||||
os.makedirs(GLOBAL.defaultConfigDirectory)
|
if arguments.use_local_config:
|
||||||
|
sys.exit()
|
||||||
if Path("config.json").exists():
|
if Path(arguments.config).exists():
|
||||||
GLOBAL.configDirectory = Path("config.json")
|
GLOBAL.configDirectory = Path(arguments.config)
|
||||||
|
else:
|
||||||
|
VanillaPrint("custom config",arguments.config,"not found. Exiting.")
|
||||||
|
sys.exit()
|
||||||
else:
|
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:
|
try:
|
||||||
GLOBAL.config = Config(GLOBAL.configDirectory).generate()
|
GLOBAL.config = Config(GLOBAL.configDirectory).generate()
|
||||||
except InvalidJSONFile as exception:
|
except InvalidJSONFile as exception:
|
||||||
|
@ -274,9 +284,6 @@ def main():
|
||||||
|
|
||||||
sys.argv = sys.argv + GLOBAL.config["options"].split()
|
sys.argv = sys.argv + GLOBAL.config["options"].split()
|
||||||
|
|
||||||
arguments = Arguments.parse()
|
|
||||||
GLOBAL.arguments = arguments
|
|
||||||
|
|
||||||
if arguments.set_filename:
|
if arguments.set_filename:
|
||||||
Config(GLOBAL.configDirectory).setCustomFileName()
|
Config(GLOBAL.configDirectory).setCustomFileName()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
@ -362,4 +369,4 @@ if __name__ == "__main__":
|
||||||
print(GLOBAL.log_stream.getvalue())
|
print(GLOBAL.log_stream.getvalue())
|
||||||
|
|
||||||
if not GLOBAL.arguments.quit: input("\nPress enter to quit\n")
|
if not GLOBAL.arguments.quit: input("\nPress enter to quit\n")
|
||||||
|
|
||||||
|
|
|
@ -153,9 +153,15 @@ class Arguments:
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Just saved posts into a the POSTS.json file without downloading"
|
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 == []:
|
if arguments == []:
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
else:
|
else:
|
||||||
return parser.parse_args(arguments)
|
return parser.parse_args(arguments)
|
||||||
|
|
Loading…
Reference in a new issue