This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganized modules; Reformatted docstrings to numpy docstrings; Refa…
…ctored primary entrypoint to docopt from argparse
- Loading branch information
1 parent
891edcd
commit c574886
Showing
12 changed files
with
311 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
from .redirects import * | ||
from .youtube_utilities import * | ||
from .command_line_utility import * | ||
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,58 @@ | ||
import argparse | ||
from .youtube_utilities import download | ||
from .redirects import trace | ||
from .ssl_utilities import check_ssl_expiry | ||
import sys | ||
|
||
import os | ||
|
||
def main(): | ||
# Setting up Main Argument Parser | ||
main_parser = argparse.ArgumentParser(description="A set of python web utility scripts") | ||
main_parser.add_argument("-v",'--version', action='version', version='kuws V0.0.1') | ||
|
||
# Setting up the main subparser | ||
subparsers = main_parser.add_subparsers(help="Available commands found below, for more info on a command use: python main.py <command> -h") | ||
"""The primary entrypoint for the kuws script. | ||
This module's main function contains all the argument | ||
parsing for the kuws script. | ||
"""Code below handles 'redirects' command in the main script | ||
i.e. >python command_line_utility.py redirects or kuws redirects | ||
""" | ||
redirects_parser = subparsers.add_parser('redirects', | ||
help='Allows you to trace redirects and get other information') | ||
Functions | ||
--------- | ||
main: | ||
Primary entrypoint for the kuws script. | ||
redirects_parser.add_argument('-u', "--url", | ||
required=True, help='usage: kuws redirects -u <url>; Lets you see the trace for a url', nargs='?', dest="trace_url") | ||
Module Variabes | ||
--------------- | ||
usage : str | ||
A variable that defines the argument parsing for the script in standard POSIX format. | ||
"""Code below handles 'ssl' command in the main script | ||
i.e. >python command_line_utility.py ssl or kuws ssl | ||
""" | ||
redirects_parser = subparsers.add_parser('ssl', | ||
help='Allows you to see ssl information for provided hostname') | ||
""" | ||
|
||
redirects_parser.add_argument('-u', "--hostname", type=str, | ||
required=True, help='usage: kuws ssl -u <url>; input hostname to use with other arguments', nargs='?', dest="ssl_url") | ||
# Python Standard library | ||
import argparse | ||
import sys | ||
import os | ||
|
||
redirects_parser.add_argument('-e', "--expiry", | ||
required=False, nargs="?", default=False, type=bool, help='usage: kuws ssl -u <url> -e=True; input hostname to use with other arguments', dest="ssl_expiry") | ||
|
||
|
||
# External Dependencies | ||
from docopt import docopt | ||
|
||
# Print help if no argument is provided | ||
if len(sys.argv)==1: | ||
main_parser.print_help() | ||
# Internal Dependencies | ||
from .utilities.youtube import download | ||
from .utilities.redirects import trace | ||
from .utilities.ssl import check_ssl_expiry | ||
|
||
""" | ||
======================================================================== | ||
Argument parsing | ||
======================================================================== | ||
""" | ||
# Obligatory argument parsing, setting arguments to args for later use | ||
args = main_parser.parse_args() | ||
usage = """Kieran's Useful Web Scripts; A set of python web utility scripts. | ||
try: | ||
# if args.trace_url: | ||
# trace(args.trace_url, print_response=True) | ||
if args.ssl_expiry: | ||
print(check_ssl_expiry(args.ssl_url)) | ||
except AttributeError: #For some ungodly reason argparse throws a hissy fit for daring to check namespace variables | ||
pass | ||
except Exception as identifier: | ||
print("Exception in URL trace with error: {}".format(identifier)) | ||
Usage: | ||
kuws --version | ||
kuws (-h | --help) | ||
kuws ssl <url> [-e] | ||
kuws redirects <url> [-t] | ||
Options: | ||
-h --help Show this help message and exit | ||
-v --version Show program's version number and exit | ||
-e --expiry If specified will check the expiry | ||
-t --trace If specified will show the full trace of the provided url | ||
# ================================= Commenting out youtube subparsing code until pytube is fixed on windows ================================= # | ||
""" | ||
|
||
# """Code below handles 'youtube' command in the main script | ||
# i.e. >python main.py youtube | ||
# """ | ||
# youtube_parser = subparsers.add_parser('youtube', argument_default='-m', | ||
# help='Allows you to interact with youtube videos') | ||
# youtube_parser.add_argument('-d', "--download", | ||
# help='usage: python main.py youtube -d <url>; Lets you download a specified youtube video', nargs='?', dest="download_url") | ||
def main(): | ||
"""Primary entrypoint for the kuws script.""" | ||
args = docopt(usage, version="kuws V0.0.4") # Grab arguments for parsing | ||
|
||
# youtube_parser.add_argument('-p', "--path", default=".", | ||
# help='usage: python main.py youtube -d <url> -p /downloads; Lets you set a path to download', nargs='?', dest="download_path") | ||
if args["ssl"]: # Begin parsing for ssl subcommand | ||
if args["--expiry"]: # If -e or --expiry is specified | ||
check_ssl_expiry(args["<url>"], print_result=True) | ||
|
||
if args["redirects"]: # Begin parsing for redirects subcommand | ||
if args["--trace"]: # If -t or --trace is specified | ||
trace(args["<url>"], print_result=True) | ||
|
||
# #TODO: Write youtube parsing download parsing properly | ||
# try: | ||
# if (args.download_url and not args.download_path): # If no -p was specified | ||
# print("video will be downloaded to script source folder: {}".format(os.getcwd())) | ||
# download(args.download_url[0], '.') | ||
# else: | ||
# print("video will be downloaded to specified directory: {}".format(args.download_path[0])) | ||
# download(args.download_url[0], args.download_path[0]) | ||
# except AttributeError: #For some ungodly reason argparse throws a hissy fit for daring to check namespace variables | ||
# pass | ||
# except Exception as identifier: | ||
# print("exception in download path with error: {}".format(identifier)) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .redirects import * | ||
from .youtube import * | ||
from .ssl import * |
Oops, something went wrong.