From 6860f7bb312d56cc4f2965ef455112ae510b25cf Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Sat, 6 May 2017 16:32:06 +0200 Subject: [PATCH] Enhanced docstrings, commented an unclear bit of my contribution. --- slideslurp/__init__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/slideslurp/__init__.py b/slideslurp/__init__.py index a36cb74..4166888 100644 --- a/slideslurp/__init__.py +++ b/slideslurp/__init__.py @@ -8,7 +8,10 @@ import requests import reportlab.pdfgen.canvas 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" parser = argparse.ArgumentParser(description=descr) @@ -18,13 +21,22 @@ def parse_args(): help='force the output file name') 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: path = urllib.parse.urlparse(args.url[0]).path args.out = '%s.pdf'%path[path.find('/', 1) + 1:] return args def main(): - """ Main function. """ + """ Main function of the program. + Uses the global command-line arguments (not custom ones)! """ args = parse_args() res = requests.get(args.url[0])