Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Commit

Permalink
Reorganized modules; Reformatted docstrings to numpy docstrings; Refa…
Browse files Browse the repository at this point in the history
…ctored primary entrypoint to docopt from argparse
  • Loading branch information
Descent098 committed Oct 20, 2019
1 parent 891edcd commit c574886
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 180 deletions.
21 changes: 15 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# Changelog
---

# June 23rd
## October 20th 2019

Merged V0.0.5 to master
- Reorganized modules
- Reformatted docstrings to numpy docstrings
- Refactored primary entrypoint to docopt from argparse

## June 23rd 2019

Merged v0.0.4 to master
- Added SSL argument to main parser
- refactored and updated inline documentation
- Added command line entrypoint to allow for direct calling
- Removed Youtube command for time being while pytube sorts out issues

# April 20th 2019
## April 20th 2019

Merged V0.0.3 to Master
Included:
- Better Packaging; Fixed Pip install pathing issues

## April 18th 2019

# April 18th 2019
Merged V0.0.2 to Master
Included:
- Better Packaging; can use functions via direct importing
Expand All @@ -24,5 +32,6 @@ Included:
- Basic URL tracing
- Youtube video downloading

# January 7th 2019
V0.0.1 initial commit on github
## January 7th 2019

V0.0.1 initial commit on github
3 changes: 0 additions & 3 deletions kuws/__init__.py
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.
118 changes: 44 additions & 74 deletions kuws/command_line_utility.py
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))
63 changes: 0 additions & 63 deletions kuws/redirects.py

This file was deleted.

16 changes: 0 additions & 16 deletions kuws/ssl_utilities.py

This file was deleted.

3 changes: 3 additions & 0 deletions kuws/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .redirects import *
from .youtube import *
from .ssl import *

0 comments on commit c574886

Please sign in to comment.