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

Let's do flags to it

981671803bac965e153ae6d707aa04da?s=47 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

981671803bac965e153ae6d707aa04da?s=128

Liene

August 27, 2015
Tweet

More Decks by Liene

Other Decks in Programming

Transcript

  1. None
  2. None
  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
  4. PROBLEMS • Feelings got in the way of my motivation

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

    • Getting started on something is awful anyway
  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
  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
  8. ASSETS • Ceaseless curiosity

  9. ASSETS • Ceaseless curiosity • Unanswered questions

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

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

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

    facilitator (and his friendly persistence) • An appreciation for the absurd
  13. Down the rabbit hole! • Wanted to do something with

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

    an API (because I haven’t before)
  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?
  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
  17. APIs, though • Secret crush on Dark Sky

  18. APIs, though • Secret crush on Dark Sky • Turns

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

    out people with APIs will give you the API key(s to their heart)
  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']
  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
  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)
  23. Bring me the argparse • How do command-line flags work

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

    in Python? • Lots of ways
  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)
  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
  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
  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
  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
  30. arg, but the good kind # First, we make a

    parser with argparse: parser = argparse.ArgumentParser(description = 'Specify optional preferences.')
  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'])
  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()
  33. ~*~ definitely ~*~ ~*~ not the worst ~*~*

  34. LIVE COMMAND LINE ⏰

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