The brilliant kobodl Python package allows you to interact with your Kobo account programmatically. You can list all the books you've purchased, download them, and - as of version 0.12.0 - view your wishlist.
Here's a rough and ready Python script which will tell you when any the books on your wishlist have dropped below a certain amount.
Prerequisites
- Install kobodl following their guide.
- Log in with your account by running
kobodl user add - Check that the configuration file is saved in the default location
/home/YOURUSERNAME/.config/kobodl.json
Get your wishlist
The kobodl function GetWishList() takes a list of users and returns a generator. The generator contains the book's name and author. The price is a string (for example 5.99 GBP) so needs to be split at the space.
Here's a quick proof of concept:
Python 3
import kobodl wishlist = kobodl.book.actions.GetWishList( kobodl.globals.Settings().UserList.users ) for book in wishlist: print( book.Title + " - " + book.Author + " " + book.Price.split()[0] )
Sort the wishlist
Using Pandas, the data can be added to a dataframe and then sorted by price:
Python 3
import kobodl import pandas as pd # Set up the lists items = [] prices = [] ids = [] wishlist = kobodl.book.actions.GetWishList( kobodl.globals.Settings().UserList.users ) for book in wishlist: items.append( book.Title + " - " + book.Author ) prices.append( float( book.Price.split()[0] ) ) ids.append( book.RevisionId ) # Place into a DataFrame all_items = zip( ids, items, prices ) book_prices = pd.DataFrame( list(all_items), columns = ["ID", "Name", "Price"]) book_prices = book_prices.reset_index() # Get books cheaper than three quid cheap_df = book_prices[ book_prices["Price"] < 3 ]
Create the Message
This will write the body text of the email. It gives you the price, book details, and a search link to buy the book.
Python 3
from urllib.parse import quote_plus # Search Prefix website = "https://www.kobo.com/gb/en/search?query=" # Email Body message = "" for index, row in cheap_df.sort_values("Price").iterrows(): name = row["Name"] price = str(row["Price"]) link = website + quote_plus( name ) message += "£" + price + " - " + name + "\n" + link + "\n\n"
Send an Email
Python makes it fairly easy to send an email - assuming you have a co-operative mailhost.
Python 3
import smtplib from email.message import EmailMessage # Send Email def send_email(message): email_user = 'you@example.com' email_password = 'P@55w0rd' to = 'destination@example.com' msg = EmailMessage() msg.set_content(message) msg['Subject'] = "Kobo price drops" msg['From'] = email_user msg['To'] = to server = smtplib.SMTP_SSL('example.com', 465) server.ehlo() server.login(email_user, email_password) server.send_message(msg) server.quit() send_email( message )
Setting the settings
When running as a script, it is necessary to ensure the settings are correctly initialised.
Python 3
from kobodl.settings import Settings my_settings = Settings() kobodl.Globals.Settings = my_settings
The End Result
I have a cron job which runs this every morning. It sends an email like this:
Next Steps
Some possible ideas. If you can code these, let me know!
- Save the prices so it sees if there's been a drop since yesterday.
- Compare prices to Amazon for eBook Arbitrage.
- Automatically buy any book that hits 99p.
Happy reading!
One thought on “Get alerted when your Kobo wishlist books drop in price”
I want to extricate my reading habit from Amazon.
| Reply to original comment on www.stephenparks.org
More comments on Mastodon.