Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's do flags to it

Liene
August 27, 2015

Let's do flags to it

Command line scripts, flags, APIs, argparse, and a totally legitimate excuse to use 🍃👯💨

Thursday 5-minute talk at Recurse Center, August 2015

Liene

August 27, 2015
Tweet

More Decks by Liene

Other Decks in Programming

Transcript

  1. View Slide

  2. View Slide

  3. Let’s do flags to it
    Command line scripts, flags, APIs, argparse, and a
    totally legitimate excuse to use
    Liene Verzemnieks, 27 Aug 2015, Recurse Center
    @li3n3

    View Slide

  4. PROBLEMS
    • Feelings got in the way of my motivation

    View Slide

  5. PROBLEMS
    • Feelings got in the way of my motivation
    • Getting started on something is awful anyway

    View Slide

  6. PROBLEMS
    • Feelings got in the way of my motivation
    • Getting started on something is awful anyway
    • THERE IS SO MUCH I DON’T KNOW

    View Slide

  7. PROBLEMS
    • Feelings got in the way of my motivation
    • Getting started on something is awful anyway
    • THERE IS SO MUCH I DON’T KNOW
    • how do you even make something you don’t
    know how to make

    View Slide

  8. ASSETS
    • Ceaseless curiosity

    View Slide

  9. ASSETS
    • Ceaseless curiosity
    • Unanswered questions

    View Slide

  10. ASSETS
    • Ceaseless curiosity
    • Unanswered questions
    • Tom the facilitator

    View Slide

  11. ASSETS
    • Ceaseless curiosity
    • Unanswered questions
    • Tom the facilitator (and his friendly persistence)

    View Slide

  12. ASSETS
    • Ceaseless curiosity
    • Unanswered questions
    • Tom the facilitator (and his friendly persistence)
    • An appreciation for the absurd

    View Slide

  13. Down the rabbit hole!
    • Wanted to do something with an API

    View Slide

  14. Down the rabbit hole!
    • Wanted to do something with an API (because I
    haven’t before)

    View Slide

  15. Down the rabbit hole!
    • Wanted to do something with an API (because I
    haven’t before)
    • Wait, how do command-line flags etc. work?

    View Slide

  16. Down the rabbit hole!
    • Wanted to do something with an API (because I
    haven’t before)
    • Wait, how do command-line flags etc. work?
    • Tom said maybe I could do emoji to it

    View Slide

  17. APIs, though
    • Secret crush on Dark Sky

    View Slide

  18. APIs, though
    • Secret crush on Dark Sky
    • Turns out people with APIs will give you the API
    key

    View Slide

  19. APIs, though
    • Secret crush on Dark Sky
    • Turns out people with APIs will give you the API
    key(s to their heart)

    View Slide

  20. APIs, though
    • Secret crush on Dark Sky
    • Turns out people with APIs will give you the API
    key(s to their heart)
    • apikey = os.environ['DARKSKY_API_KEY']

    View Slide

  21. APIs, though
    • Secret crush on Dark Sky
    • Turns out people with APIs will give you the API
    key(s to their heart)
    • apikey = os.environ[‘DARKSKY_API_KEY']
    • Liene + Dark Sky = BFFs 5eva

    View Slide

  22. APIs, though
    • Secret crush on Dark Sky
    • Turns out people with APIs will give you the API
    key(s to their heart)
    • apikey = os.environ[‘DARKSKY_API_KEY']
    • Liene + Dark Sky = BFFs 5eva
    • (also graphs)

    View Slide

  23. Bring me the argparse
    • How do command-line flags work in Python?

    View Slide

  24. Bring me the argparse
    • How do command-line flags work in Python?
    • Lots of ways

    View Slide

  25. Bring me the argparse
    • How do command-line flags work in Python?
    • Lots of ways (to find more ways than you need,
    just tweet)

    View Slide

  26. Bring me the argparse
    • How do command-line flags work in Python?
    • Lots of ways (to find more ways than you need,
    just tweet)
    • Argparse is one way

    View Slide

  27. Bring me the argparse
    • How do command-line flags work in Python?
    • Lots of ways (to find more ways than you need,
    just tweet)
    • Argparse is one way, and may give you
    superpowers

    View Slide

  28. Bring me the argparse
    • How do command-line flags work in Python?
    • Lots of ways (to find more ways than you need,
    just tweet)
    • Argparse is one way, and may give you
    superpowers
    • MEGA GIGANTIC DOCS OH GOSH

    View Slide

  29. Bring me the argparse
    • How do command-line flags work in Python?
    • Lots of ways (to find more ways than you need,
    just tweet)
    • Argparse is one way, and may give you
    superpowers
    • MEGA GIGANTIC DOCS OH GOSH, but!
    • Super fun little tutorial

    View Slide

  30. arg, but the good kind
    # First, we make a parser with argparse:
    parser = argparse.ArgumentParser(description = 'Specify optional preferences.')

    View Slide

  31. arg, but the good kind
    # First, we make a parser with argparse:
    parser = argparse.ArgumentParser(description = 'Specify optional preferences.')
    parser.add_argument('--location', '-l', help = 'Specify a particular location')
    parser.add_argument('--timeframe', '-t', help = 'What timeframe to print out',
    choices = ['currently', 'minutely', 'hourly', 'daily'])

    View Slide

  32. arg, but the good kind
    # First, we make a parser with argparse:
    parser = argparse.ArgumentParser(description = 'Specify optional preferences.')
    parser.add_argument('--location', '-l', help = 'Specify a particular location')
    parser.add_argument('--timeframe', '-t', help = 'What timeframe to print out',
    choices = ['currently', 'minutely', 'hourly', 'daily'])
    # Put all those arguments into something we can use!
    args = parser.parse_args()

    View Slide

  33. ~*~ definitely ~*~
    ~*~ not the worst ~*~*

    View Slide

  34. LIVE COMMAND LINE

    View Slide

  35. YES!
    https://github.com/li3n3/weather_balloon

    View Slide