Skip to content

Instantly share code, notes, and snippets.

@gnur
Created January 14, 2020 14:47
Show Gist options
  • Save gnur/8b2777f11bed594a0a988931637a0c0f to your computer and use it in GitHub Desktop.
Save gnur/8b2777f11bed594a0a988931637a0c0f to your computer and use it in GitHub Desktop.
Tracking reading progress with firebase functions/hosting, svelte and concrete.css

Tracking reading progress with firebase functions/hosting, svelte and concrete.css

Ever since I discovered goodreads I've been almost obsessed with tracking what I read and obtaining as much stats as possible.

At first, to get real time insights in my reading progress of books, I looked into extracting information from my kindle. Whispersync syncs the progress of the books I'm reading to something at Amazon. However, there is no public API to get this information out. I actually tried sniffing the traffic and using phantomJS to extract stuff from the cloud reader. But this all felt a bit hacky.

However, this all changed when I switched to reading my books with librera on my Android phone. (I switched to reading on my phone because I have it with me all the time)
It can sync your reading progress to Google Drive and after a short examination of the files stored on Google Drive I found out it was simply storing JSON.

Example of this file:

{
   "V_E_Schwab-Vicious.epub":{
      "cp":false,
      "d":0,
      "dc":false,
      "dp":false,
      "lk":1,
      "p":0.5742,
      "s":120,
      "sp":false,
      "t":1565986186029,
      "x":0,
      "y":0,
      "z":100
   },
   "V_E_Schwab-Vengeful.epub":{
      "cp":false,
      "d":0,
      "dc":false,
      "dp":false,
      "lk":1,
      "p":1,
      "s":120,
      "sp":false,
      "t":1566495998899,
      "x":0,
      "y":0,
      "z":100
   }
}

With some basic testing I Found out t is the unix timestamp of the update and p is the progress (where 0.57 means you are at 57%).

I quickly threw together a firebase cloud function to load this JSON file from google drive (apparently it is enough to share the file with ${firebase-project-name}@appspot.gserviceaccount.com to grant your cloud function access).

This function now loads this file every 30 minutes, parses every book, checks if the current "stats" from Librera are stored in firestore already and otherwise adds it marks it as finished if you are over 98.5%.

showing progress

I found this awesome tutorial on how to use firebase with svelte and threw together a small site to show live progress of my reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment