Day 18 - Adding Command Line Args to Brandywine

In an attempt to make the Brandywine script self contained, I’ve decided to use command line arguments to make certain calls to the Rotten Tomatoes API. I’m using argparse as my method of generating command flags to use with the script. Here’s what I’ve got thus far:

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Rotten Tomatoes cli')
    parser.add_argument('-b', '--boxoffice', \
        action='store_true', help='lists current box office movies.')
    parser.add_argument('-t', '--intheaters', \
        action='store_true', help='lists movies currently in theaters.')
    parser.add_argument('-s', '--search', \
        metavar='movie', help='query the movie database')
    args = parser.parse_args()

I spent some time combing through the Python documentation trying to comprehend exactly how the argparse module is used. The add_argument method adds the command line arg with long and short versions, offers help information, and with certain flags, you can default to ‘no arguments passed’ as a result of using that flag. There’s more for me to finish reading about it, but so far, it’s straightforward.

Jason T Clark

Jason T Clark

Father. Musician. Gamer. Coder.

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin