Skip to content

Instantly share code, notes, and snippets.

@christinac
christinac / book_extractor.py
Created January 1, 2016 02:51
How the book-extraction magic happens before all those books get dropped
#!/usr/bin/python
from datetime import datetime
import json
import re
from xml.sax.saxutils import unescape
import models
from bookkit import Book, BookNotFoundException
from utils.gmailservice import GmailService # modified version of https://developers.google.com/gmail/api/quickstart/python
ruby -r json -r open-uri -e 'last = nil; rem_t = nil; while true; dollars=(JSON.parse(open("https://pledge.mayday.us/r/total").read)["totalCents"] - 100000000)/100; rem = 5000000-dollars; puts "$#{dollars} raised. $#{rem} to go."; (last = dollars; sleep 60; next) unless last; delta_rem_t = (rem.to_f / ((dollars - last) * 60)); rem_t = rem_t ? (0.85 * rem_t + 0.15 * delta_rem_t) : delta_rem_t; puts " $#{dollars-last} in the last 60 seconds. #{rem_t} hours to go."; last = dollars; sleep 60 ; end'