Did you know: programmers convert coffe to code?

If you like my articles, support me with a small amount.


Buy me a coffee

Goodreads Giveaways automated

I like to read books and I have time on the train every day to read. And I love free books. And the Giveaways of Goodreads are a great thing to get free books.

But this is a blog of a software developer — why would I write about free books?

Well, the story is two-fold.

General about giveaways

Currently, there is two kinds of giveaways: print books and Kindle books.

The drawback is, that I like to read digital editions but for Hungary (where I live) only print books are available. And this is a bit bad.

However, print books are OK too to win because the trees are already dead and the book is available so I have no bad feelings about reading a paper book. And if I am finished, I can pass the books on, for example to the local library. Honestly, it would be a shame to ask for money for the books I’ve got without any investment.

One request from Goodreads and the authors of such freebie books is to write an honest review of the book once finished reading. This is one thing I do anyway: if I finished a book I’m writing a review of it.

The Kindle giveaways would be way better for me and for the authors because in this case, you do not have any shipping time nor shipping cost. And of course, no dead trees and storage space in your flat/house where books gather dirt and you have to take care of them and so on. The pity is, Goodreads evaluates possible other countries since a year but I do not see any progress. I think the lawyers (if there are any) are just sitting in their office and read newspapers instead of evaluating anything. A far worse scenario would be if Goodreads wants to have a “big bang” release of the remaining countries. This is a bad idea because many people are waiting to get access to the digital giveaways. Besides this, such a giveaway can improve the reviews at amazon.com too because you are asked at the end of the book how would you rate it (for Goodreads or for Amazon) and because you have it in your account, you will write two reviews (alternatively copy-paste one to the other site).

The coding part

Now it gets interesting because I am lazy and I do not have much time when I am on-line to see through all the books you can win and see if the genre is OK for me (for example I do not like romances) or it is not a follow-up book of a series (it is really annoying if you read a book but you do not know the characters or the main plot).

Therefore, I have written a small script (around 300 LoC Python code) which takes care of all this for me. No Selenium or any other browser-simulation is involved: it is pure Python with BeautifulSoup and requests.

I did not implement a login feature because I do not need it. But you can guess, you need some authentication and authorization to go and enter giveaways without any manual interaction.

The script works basically how I do entering giveaways: I go through the list and look for books I am not entered already. Then I open the book’s description and see if there is a language available and if it is in one of the languages I can read. If not, I skip the book. The second criterium is that the book should be the #1 book of a series or it should be a single book. This can be easily deduced from the title of the book.

  • I go through the list and look for books I have not entered already.
  • I open the book’s description and see if there is a language available and if it is in one of the languages I can read. If not, I skip the book.
  • The second criterium is that the book should be the #1 book of a series or it should be a single book. This can be easily deduced from the title of the book.
  • The third criterium is the genre. If it is something I dislike, I skip the book.
  • If all the criteria are met I enter the giveaway, select the address I want the book to be shipped to (my main address) and then hit submit and I am in.

The hardest part of these steps is the filtering by genre. You cannot select genres for a book if you add it to Goodreads (and I find it a pity but understand because some genres are very subjective). Therefore, I have to gather this information from the user-provided information. This means you can add books to a bookshelf and this is displayed on the book’s page if any are available. The problem with this is that I can accept books which are romances but nobody shelved them as romances. That’s a pity but I have to live with it currently.

If I want to think the solution of genre-filtering a bit further, I could extend the application to look for the book at Amazon, see if there is a genre available or just create a machine learning algorithm which guesses from the sentiment of the book’s description what the genre might be.

Beside all this there are edge cases: no language present, my extraction of the series number fails because of any reason. For this, it is viable to see the results and not just skip the books. That’s why I create an export in HTML format of the whole run. If the script skipped a book it creates a link where I can review the book’s information and enter the giveaway manually.

The code

Sorry, but I am not planning to share the code with you. It took some investment time to get the script up and running — and it is not perfect, only for me. If you really insist, we can negotiate a solution where you support me (through buying one of my books or book a live session) and I share the code with you.

However, one information I can share with you: I implemented a simple random “sleep” between requests to keep the servers calm. It takes much more time to finish, but on average I deal with 100 books and if every request waits 3 seconds then the script is done in 10 minutes which is good enough.

Conclusion

It is good to be lazy and a software developer. In the long-run I saved much more time through automated giveaways than the coding part and every time I remember to see what’s available I start my script and it selects almost 50% of the books and for the rest, it provides a list.

A future step would be to add an option to automatically enter giveaways. Sometimes I find books in the list of skipped I already know from previous runs and I want to enter them, or the title sounds interesting and I do not care about genre or missing language. Alternatively, a step where I download the cover images for the books would be nice so I can decide based on the cover too.

GHajba
 

Senior developer, consultant, author, mentor, apprentice. I love to share my knowledge and insights what I achieve through my daily work which is not trivial -- at least not for me.

Click Here to Leave a Comment Below 0 comments