Skip to content

Instantly share code, notes, and snippets.

@axju
Created August 15, 2021 11:08
Show Gist options
  • Save axju/5b5327cb359a1d8a125733568046819d to your computer and use it in GitHub Desktop.
Save axju/5b5327cb359a1d8a125733568046819d to your computer and use it in GitHub Desktop.
This is the source to my video: https://youtu.be/7XJMe8q6JZE
import logging
from argparse import ArgumentParser
logger = logging.getLogger(__name__)
def data():
logger.info('run data func')
def video():
logger.info('run video func')
def setup_logger(level=0):
logger = logging.getLogger()
levels = [logging.WARNING, logging.INFO, logging.DEBUG]
level = levels[level or 0]
logger.setLevel(level)
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter('%(levelname)s - %(message)s'))
logger.addHandler(ch)
def main():
funcs = {
'data': data,
'video': video,
}
parser = ArgumentParser()
parser.add_argument('-v', '--verbose', action='count')
parser.add_argument('action', nargs='?', choices=funcs.keys())
args = parser.parse_args()
setup_logger(args.verbose)
funcs.get(args.action, parser.print_help)()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment