add try/except for missing config file
This commit is contained in:
parent
275f16e997
commit
beac59d440
|
@ -43,7 +43,7 @@ parser.add_argument(
|
||||||
"--archive-deleted", action="store_true", help="Only archive toots that are being deleted"
|
"--archive-deleted", action="store_true", help="Only archive toots that are being deleted"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--config", action="store", metavar="filepath", default="config.yaml", help="Filepath of your config file, absolute or relative to the current directory. If no --config path is provided, ephemetoot will use 'config.yaml'."
|
"--config", action="store", metavar="filepath", default="config.yaml", help="Filepath of your config file, absolute or relative to the current directory. If no --config path is provided, ephemetoot will use 'config.yaml'in the current directory"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--datestamp", action="store_true", help="Include a datetime stamp for every action (e.g. deleting a toot)"
|
"--datestamp", action="store_true", help="Include a datetime stamp for every action (e.g. deleting a toot)"
|
||||||
|
@ -52,7 +52,7 @@ parser.add_argument(
|
||||||
"--hide-skipped", "--hide_skipped", action="store_true", help="Do not write to log when skipping saved toots"
|
"--hide-skipped", "--hide_skipped", action="store_true", help="Do not write to log when skipping saved toots"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--init", action="store_true", help="Initialise creation of a config file saved in the current directory."
|
"--init", action="store_true", help="Create a config file that is saved in the current directory"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--pace", action="store_true", help="Slow deletion actions to match API rate limit to avoid pausing"
|
"--pace", action="store_true", help="Slow deletion actions to match API rate limit to avoid pausing"
|
||||||
|
@ -73,7 +73,7 @@ parser.add_argument(
|
||||||
"--time", action="store", metavar=('hour', 'minute'), nargs="*", help="Hour and minute to schedule: e.g. 9 30 for 9.30am"
|
"--time", action="store", metavar=('hour', 'minute'), nargs="*", help="Hour and minute to schedule: e.g. 9 30 for 9.30am"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--version", action="store_true", help="Display the version number"
|
"--version", action="store_true", help="Display the version numbers of the installed and latest versions"
|
||||||
)
|
)
|
||||||
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
@ -85,25 +85,31 @@ else:
|
||||||
config_file = os.path.join( os.getcwd(), options.config )
|
config_file = os.path.join( os.getcwd(), options.config )
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if options.init:
|
try:
|
||||||
func.init()
|
|
||||||
elif options.version:
|
if options.init:
|
||||||
func.version(vnum)
|
func.init()
|
||||||
elif options.schedule:
|
elif options.version:
|
||||||
func.schedule(options)
|
func.version(vnum)
|
||||||
else:
|
elif options.schedule:
|
||||||
if not options.quiet:
|
func.schedule(options)
|
||||||
print('')
|
else:
|
||||||
print('============= EPHEMETOOT v' + vnum + ' ================')
|
if not options.quiet:
|
||||||
print('Running at ' + str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') ))
|
print('')
|
||||||
print('================================================')
|
print('============= EPHEMETOOT v' + vnum + ' ================')
|
||||||
print('')
|
print('Running at ' + str( datetime.now(timezone.utc).strftime('%a %d %b %Y %H:%M:%S %z') ))
|
||||||
if options.test:
|
print('================================================')
|
||||||
print("This is a test run...\n")
|
print('')
|
||||||
with open(config_file) as config:
|
if options.test:
|
||||||
for accounts in yaml.safe_load_all(config):
|
print("This is a test run...\n")
|
||||||
for user in accounts:
|
with open(config_file) as config:
|
||||||
func.checkToots(user, options)
|
for accounts in yaml.safe_load_all(config):
|
||||||
|
for user in accounts:
|
||||||
|
func.checkToots(user, options)
|
||||||
|
|
||||||
|
except FileNotFoundError as err:
|
||||||
|
print("🕵️ Missing config file")
|
||||||
|
print("Run \033[92mephemetoot --init\033[0m to create a new one\n")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue