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
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
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
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']
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
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)
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
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
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
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'])
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()