improve maintainability and reduce code cognitive complexity (#49)
This commit is contained in:
parent
d3e68d0e70
commit
da390ee8a3
@ -91,26 +91,29 @@ def _known_urls(obj, args):
|
|||||||
|
|
||||||
def _get(obj, args):
|
def _get(obj, args):
|
||||||
if args.get.lower() == "url":
|
if args.get.lower() == "url":
|
||||||
return obj.get()
|
output = obj.get()
|
||||||
|
|
||||||
if args.get.lower() == "archive_url":
|
elif args.get.lower() == "archive_url":
|
||||||
return obj.get(obj.archive_url)
|
output = obj.get(obj.archive_url)
|
||||||
|
|
||||||
if args.get.lower() == "oldest":
|
elif args.get.lower() == "oldest":
|
||||||
return obj.get(obj.oldest())
|
output = obj.get(obj.oldest())
|
||||||
|
|
||||||
if args.get.lower() == "latest" or args.get.lower() == "newest":
|
elif args.get.lower() == "latest" or args.get.lower() == "newest":
|
||||||
return obj.get(obj.newest())
|
output = obj.get(obj.newest())
|
||||||
|
|
||||||
if args.get.lower() == "save":
|
elif args.get.lower() == "save":
|
||||||
return obj.get(obj.save())
|
output = obj.get(obj.save())
|
||||||
|
|
||||||
return "Use get as \"--get 'source'\", 'source' can be one of the followings: \
|
else:
|
||||||
\n1) url - get the source code of the url specified using --url/-u.\
|
output = "Use get as \"--get 'source'\", 'source' can be one of the followings: \
|
||||||
\n2) archive_url - get the source code of the newest archive for the supplied url, alias of newest.\
|
\n1) url - get the source code of the url specified using --url/-u.\
|
||||||
\n3) oldest - get the source code of the oldest archive for the supplied url.\
|
\n2) archive_url - get the source code of the newest archive for the supplied url, alias of newest.\
|
||||||
\n4) newest - get the source code of the newest archive for the supplied url.\
|
\n3) oldest - get the source code of the oldest archive for the supplied url.\
|
||||||
\n5) save - Create a new archive and get the source code of this new archive for the supplied url."
|
\n4) newest - get the source code of the newest archive for the supplied url.\
|
||||||
|
\n5) save - Create a new archive and get the source code of this new archive for the supplied url."
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
def args_handler(args):
|
def args_handler(args):
|
||||||
@ -123,34 +126,34 @@ def args_handler(args):
|
|||||||
% __version__
|
% __version__
|
||||||
)
|
)
|
||||||
|
|
||||||
|
obj = Url(args.url)
|
||||||
if args.user_agent:
|
if args.user_agent:
|
||||||
obj = Url(args.url, args.user_agent)
|
obj = Url(args.url, args.user_agent)
|
||||||
else:
|
|
||||||
obj = Url(args.url)
|
|
||||||
|
|
||||||
if args.save:
|
if args.save:
|
||||||
return _save(obj)
|
output = _save(obj)
|
||||||
if args.archive_url:
|
elif args.archive_url:
|
||||||
return _archive_url(obj)
|
output = _archive_url(obj)
|
||||||
if args.json:
|
elif args.json:
|
||||||
return _json(obj)
|
output = _json(obj)
|
||||||
if args.oldest:
|
elif args.oldest:
|
||||||
return _oldest(obj)
|
output = _oldest(obj)
|
||||||
if args.newest:
|
elif args.newest:
|
||||||
return _newest(obj)
|
output = _newest(obj)
|
||||||
if args.known_urls:
|
elif args.known_urls:
|
||||||
return _known_urls(obj, args)
|
output = _known_urls(obj, args)
|
||||||
if args.total:
|
elif args.total:
|
||||||
return _total_archives(obj)
|
output = _total_archives(obj)
|
||||||
if args.near:
|
elif args.near:
|
||||||
return _near(obj, args)
|
output = _near(obj, args)
|
||||||
if args.get:
|
elif args.get:
|
||||||
return _get(obj, args)
|
output = _get(obj, args)
|
||||||
message = (
|
else:
|
||||||
"You only specified the URL. But you also need to specify the operation."
|
output = (
|
||||||
"\nSee 'waybackpy --help' for help using this tool."
|
"You only specified the URL. But you also need to specify the operation."
|
||||||
)
|
"\nSee 'waybackpy --help' for help using this tool."
|
||||||
return message
|
)
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
def parse_args(argv):
|
def parse_args(argv):
|
||||||
|
Loading…
Reference in New Issue
Block a user