Enhanced docstrings, commented an unclear bit of my contribution.
This commit is contained in:
@@ -8,7 +8,10 @@ import requests
|
|||||||
import reportlab.pdfgen.canvas
|
import reportlab.pdfgen.canvas
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
""" Parse the command-line arguments. """
|
""" Parse the command-line arguments and return them as an object.
|
||||||
|
The returned object has the following properties:
|
||||||
|
- `url` (string): the URL of the slideshare to download;
|
||||||
|
- `out` (string): the output file path. """
|
||||||
descr = "Generate PDFs from Slideshare presentations"
|
descr = "Generate PDFs from Slideshare presentations"
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description=descr)
|
parser = argparse.ArgumentParser(description=descr)
|
||||||
@@ -18,13 +21,22 @@ def parse_args():
|
|||||||
help='force the output file name')
|
help='force the output file name')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# If the user doesn't specify an output filename, we'll deduce
|
||||||
|
# one from the URL. Here's an URL example:
|
||||||
|
# https://www.slideshare.net/FrisodeJong/iso-20022-for-dummies
|
||||||
|
#
|
||||||
|
# We're taking the path (`/FrisodeJong/iso-20022-for-dummies`),
|
||||||
|
# isolating the part after the second slash (the first slash
|
||||||
|
# always being at the first position), and appending `.pdf` to it.
|
||||||
if not args.out:
|
if not args.out:
|
||||||
path = urllib.parse.urlparse(args.url[0]).path
|
path = urllib.parse.urlparse(args.url[0]).path
|
||||||
args.out = '%s.pdf'%path[path.find('/', 1) + 1:]
|
args.out = '%s.pdf'%path[path.find('/', 1) + 1:]
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" Main function. """
|
""" Main function of the program.
|
||||||
|
Uses the global command-line arguments (not custom ones)! """
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
res = requests.get(args.url[0])
|
res = requests.get(args.url[0])
|
||||||
|
Reference in New Issue
Block a user