- Podcasts
- Python Bytes
- #26 How have you automated your life, or CLI, with Python?
#26 How have you automated your life, or CLI, with Python?
Python Bytes
- May 19, 2017
- 20 min
- Episode 26
About this episodeTopics covered in this episode: Two part series on interactive terminal applications How have you automated your life with python?…
- Two part series on interactive terminal applications
- How have you automated your life with python?
- Spelling with Elemental Symbols
- IDE's for beginners
- PDF Plumber
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#26 How have you automated your life, or CLI, with Python?
Hello, and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is episode 26, recorded May 16, 2017. I'm Michael Kennedy. And I'm Brian Okken. And we're here to deliver a bunch of cool news around the Python community. But before we do, I'd like to say thanks, Brian.
I'd like to say thanks to Rollbar, because once again, they're sponsoring this episode. Yay, Rollbar. Yay, Rollbar. So they're going to be at PyCon, so be sure to drop by their booth and tell them that we sent you. All right. Let's talk about the terminal. Yeah. When I think of command line interface, I mean, I use like the REPL and other terminal interfaces.
But most of the time when I'm writing applications that I think of as command line, they just have, you can launch them from the command line with flags and stuff like that. But if you wanted to do an interactive, like an interactive terminal application, like a REPL or something, I don't know how to do that.
And this is, I ran across this two-part series article, a two-part series. And the first part was just actually talking about, and this is on opensource.com. And the first article talks about four different applications that have good interface characteristics. And it started with the MySQL interface and the Python REPL, which were good, but both could be better.
And the author talked about BPython as a adds auto-completion to Python. Oh, BPython. Interesting. I've never heard of BPython. I use PTpython. Well, the article also mentions PTpython. So I was going to try both of them out and see which one I liked better. Oh, okay. You'll have to give us a report.
Yeah. There's a, apparently for MySQL, there's a MyCLI that adds context-aware completion. I don't spend enough time in a MySQL to worry about that. But then a couple others, if you're a Postgres person, there's somebody, something called PGCLI that adds fuzzy search. And then you talked about bash.
Yeah. So that was the first part. And the second part of the series talks about how to do this sort of stuff with Python. So he talks about actually taking four different libraries. There's one called the prompt toolkit that you can use that to add command line, command history, a REPL-like interface to your application.
And you can add things like command history and auto-suggestion and auto-completion, which sounds cool, actually. Yeah, that actually does sound pretty cool. And then click, which I'm familiar with using click for like options and flags, but apparently it also has a pager and the ability to launch an editor outside of it, which would be cool.
That sounds cool. Yeah, yeah. Very cool. And then a couple more pigments for syntax highlighting and fuzzy finder, which is a way to make fuzzy suggestions on whatever somebody types in. That's cool. And the nice thing is that it talks, there's an example on how to include, to hook up fuzzy finder and prompt toolkit to make the completion look nice.
It's a well-written series. And when I add interactive stuff to an application, maybe I'll check this out. Yeah, it definitely looks cool. You know, CLIs are great for automating things, right? So I found a Reddit conversation. It's not linking to an article, but it's a conversation that I thought was just outrageous for some of the things and interesting and inspiring for others.
And so some of them are totally straightforward. So there's like somebody that said, hey, I take the train to work or something. So I run a script every five minutes between five and five 30, which scrapes the train websites and sends me a notification of my train. It's on a delay or on time or canceled or something like that.
That's pretty cool, right? Yeah. Yeah. Like to your Slack channel, like you better get going. Your train's showing up early or it's late or whatever. Yeah. And then, so that was pretty standard, right? Like there's another one that's a little more playful. Like a person wrote a script to check if a nearby ice cream shop is stocking their favorite flavor by screen scraping their menu.
Oh, nice. Is my, is my ice cream in stock? Yes. All right. I'm going to get some. That person is passionate about their ice cream. Yeah. Well, have you been to Salt and Straw? Yes. I'd like something like that for Salt and Straw. That'd be great. Yeah. Yeah. For sure. Like I wouldn't want the ice cream flavor.
I would want the line length. Oh yeah, definitely. Like, so those of you who are coming here for PyCon, Salt and Straw is like this, you know, you probably heard of Voodoo Donuts, which is like a iconic donut place in Python. People, in Portland, you'll see people with like these pink boxes all over the place.
This is kind of like that. It's like, that's pretty interesting, but it also kind of weird. But anyway, there's a bunch more. I only grabbed some of them. That's pretty interesting. If you've automated something amazing, you know, go and stick it up there, throw it into the chat, the discuss on this episode page.
Yeah. Speaking of automating your life a little bit, I ran across this article and it's by the Pi Bytes people and it's called Building a Simple Birthday App with Flask SQLAlchemy. And the kind of the idea, which I loved behind it is they were tired of relying on Facebook to know when their friends, when all the birthdays are coming up.
I've never played with SQLAlchemy, so maybe I'll try this out. Yeah. Oh, that sounds really fun. Nice. So yeah, yeah, that definitely is another way to automate your life. And what we have coming up is also a, maybe an automated spelling, you might say. But before we do, let me tell you guys about Rollbar.
As you all know, I use Rollbar for all of our sites. Rollbar is constantly watching. And if something crashes on the site, I get an immediate notification, maybe in Slack, maybe my phone, all sorts of stuff. So if you run web applications, you, or even apps that you distribute, you owe it to yourself to work with Rollbar, right?
Go to rollbar.com slash Python bytes, and you can sign up. It's super easy to add like to Pyramid, Flask, Django. They have quick search for all of them. It's like really, really new work. And those guys are going to be at PyCon, just like Brian and me. And they are inviting you to stop by their booth, get some swag, check them out, get a demo, things like that.
Awesome. Yeah. I'll check out their booth at PyCon. How about you? Oh, definitely will. I'll try to give them some of my stickers. Yeah. I'm definitely going to bring a sticker over there as well. We're coming, Mike. We're coming. All right. So the thing that I have next is this blog post that got sent to us.
So the idea is that the article is spelling with elemental symbols. So we know that the periodic table has a bunch of one to two character words or letters representing elements, right? So the idea is, can you take a regular word and spell it atomically? So, you know, N, A, like capital N, lowercase a, capital H, right?
Something like that, right? So can you take the stuff that's on the periodic table and make words out of it, right? So that's basically what this does. And it sounds kind of like, kind of interesting, but there's a couple of things that are worth looking at. One is you can look at a word and you can break it up into this piece and say, okay, well, this is consists of like, maybe it's a four letter word, consists of one, one, one, one possible letter arrangements, or it could be two, one, one, or one, one, one, two, right?
Don't remember. Well, not so much the number, but the formula for it, like the concept for it. It turns out that the number of these arrangements based on the number of characters is the Fibonacci sequence. Oh, wow. Okay. Isn't that crazy? So if you've like a five letter word, there's whatever the sixth value of the Fibonacci numbers is.
That's how many possible options are. 10 letters of the 11th Fibonacci and so on. It's like N plus one, basically. Isn't that crazy? Yeah. Just, I want to randomly grab stuff off the periodically table Fibonacci. Okay. So that's pretty interesting, but it turns out like the guy was doing a bunch of work to sort of break these apart.
The really computational part is given a word, how many of these Fibonacci numbered partitionings are there, right? That's where most of the work was. So he said, okay, well, I tried to optimize it in a couple of ways and he does a lot of interesting performance profiling. So you can learn how to profile your code there, which is really cool.
It just works on its input parameters and then it gives you back a number or a value based solely on the input. You can use this idea called memoization to say, basically cache the input arguments and then the potentially expensive output. So if you get, you know, a word of length seven, well, you know, you can, you know how, what like the seventh Fibonacci arrangement of these things is and you don't ever have to compute it again.
So he's like, well, let's try this to make it faster. And it turns out that it did make it faster, but like 30%. So it went for like whatever his data set it was. It went from like 22 minutes to 60 minutes or, or something to this effect. So that was better. And then he said, all right, let's rethink this algorithm, switch to a directed acyclic graph using recursion.
And the complexity went from O2 to the N to O of N and the time to compute all these, um, these sort of weird spellings, if you will, went from 16 minutes to 10 seconds. Wow. So, which is really cool. So he takes this pretty easy to understand problem and, and works through it and does profiling, complexity analysis, memoization, recursion graphs.
It's this kind of a problem. And how do you approach it from a computer science standpoint to, and an engineering standpoint of faster is better and getting down to it. It's pretty cool. Yeah, it is really cool. And it's, there's something super rewarding about writing code that goes, it takes 22 minutes to run and getting that down to 10 seconds.
I ran across, another Reddit comment thread and this one is a discussion about a, an IDE called, I think it's Tony Thonny, T H O N N Y. Any guesses on how to pronounce that? I'm going, I'm going with Thonny. But I'm not sure. So that there's a discussion about whether or not about the merit of this particular IDE.
So actually I was just curious about what you thought about beginner editors. I did look at this and I also had mixed emotions about it. It was like interesting, but I'm not entirely sure that I would recommend it. And I don't really know why, but I definitely think it's, it's quite interesting to see what it does.
Right. So that's kind of cool that you can actually see the variables that are at work while you're writing your code. Now, obviously we don't need that these days, but you know, when you're new, like those things get lost. Right. Yeah. And so that's really nice. It has like a single button debugging experience.
Okay. Which is pretty cool. And then it has like, while you're debugging it, it has a shell and you can like type stuff in the shell, like, like a REPL basically. And it'll like, let you explore the state of the program, I believe, if I'm understanding it correctly. So those are all pretty interesting things.
Maybe it is. I mean, one thing that's cool about it is it comes with Python 3.6 built in and it's a Windows app. Okay. Right. So you just install it and you open it up and then boom, you have Python 3.6. You don't have to think about, oh my God, VCVars.bat. Where's the path? Why is this not working?
All right. Last thing. I have some salvation for the PDF people out there. So a lot, especially if you're in data science or doing web scraping and trying to get data, often it's bundled up in these reports, which are in PDFs. And the support for actually going into these PDFs and getting them out in Python has not been good.
It's really, you know, I've had a lot of people say, I've tried this, I've tried this, I've tried this. None of them work. Do you have any ideas, Michael? And I say, nope, no ideas. So there's recommendation on Twitter that I thought was really good from Dan Schorstein. And he said, hey, you should check out this thing called PDF Plumber.
So you can go in and you can extract graphs. You can debug your processing of the PDF file visually. Oh, wow. So if you're trying to extract a table, you can go and say, you'll highlight the thing I'm looking for like this. And it'll literally show you a PNG with like rectangles around the pieces you're getting.
Which is pretty cool. So you can extract a bunch of tables. You can work with the shapes. You can group stuff together. Somebody did like a master's thesis on this. And a lot of those ideas are brought into it. So if you're out there doing data science and or something where the data is wrapped up in PDFs and you've been having a hard time getting at it, check out PDF Plumber.
So the first five chapters will be, five chapters? Yeah. The first five chapters will be released unofficially in stealth mode on the 17th. Awesome. And that's tomorrow. Just in time for PyCon. Or either that or today or yesterday, depending on when people get this. It could have been three weeks ago if you listened to this very lately.
Oh, that's awesome. Yeah. Congrats. How about you? What's going on? Well, I am really looking forward to being at PyCon. I'm going to be there Thursday night. We'll have our booth there. And Thursday, Friday, Saturday, Sunday, we'll have our booth set up. People come hang out with us, come talk to us.
I'm just waiting on the final edits to publish that to the world. And I'm now working on my MongoDB for Python developers course. So I'm frantically writing as fast as I can before PyCon overwhelms me. Oh, nice. Okay. Yeah. Those are both going to be fun. Great. Cool. All right. Well, that's all I got.
That's about it for me. Yeah. Yeah. Same here, man. Well, welcome back to the US. And I will see you and everyone else at PyCon. Yeah. See you in a couple of days. All right. Bye. Bye. Thank you for listening to Python Bytes. Follow the show on Twitter via at Python Bytes. That's Python Bytes as in B-Y-T-E-S.
And get the full show notes at Python Bytes.fm. If you have a news item you want featured, just visit Python Bytes.fm and send it our way. We're always on the lookout for sharing something cool. On behalf of myself and Brian Okken, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.
