How Python helps me write book reviews
Okay, I admit, the headline is a click-bait, which was supposed to get you here, but that's only half-true. If you are interested in how Python programming language can go hand in hand with reading books and extracting quotes from them, do stay with me.
As of recently, one of my hobbies is extracting parts of the books I read, into a short paragraphs or a simple one-line quotes. This is nothing new. Not more than two decades ago, while reading required school literature, I was underlining the quotes I liked. In some cases when the book was borrowed for example, I was rewriting quotes in my notebook.
Time and technology move forward, and now I do it in a slightly different form, by underlining directly in book reader.
Now, once I finish the book, I want to get all my notes "out" of the book reader, into my text file. Once I actually extract the notes, there will be many redundant lines, related to book itself and the author, in which I am not interested in. Below is an example of three quotes, which are followed by addtional info (this is added automatically when you highlight in book reader):
Naturally, I am interested only in the quotes themselves, not in this redundant information, which follows up. This is of course analogous to many areas of our lives: desired end result is often accompanied by a completelly unneeded by-products.
For the first few books, I was removing additional info manually, while listening to some music or documentary. Soon after however, activity like this starts to drive you crazy and what do you do? Automate it! And what do we use to automate stuff nowadays? You saw it comming - Python. If I can write a program to do something instead of me, you bet I am going to do so. Related to my primary job as a verification engineer, it is often desired to automate various aspects of my daily work and those who embrace this approach, will become significantly more effective in completing their tasks.
Back to my notes extracting problem. After a quick analyses, I saw that I need to write a program which will modify my text file by removing each line starting with "====", as well as the three subsequent lines. After that, in my text file there will only be quotes from the book (useful information I was interested in, in the first place).
Effective transformation of the text is shown below:
Below is the program I wrote:
Program itself is very simple, but that is besides the point. What is important here is the way of thinking and approach to solving the problem at hand. Whenever possible, we should try to automate borring and unneeded stuff in our daily activities. This particular example shows that we can use Python to automate stuff for us in real-life, not only in our day-to-day jobs. And I'm loving it.
In what way do you use Python to automate stuff?