goodread-phat/good.py
Tyrel Souza a0089c5661 stuff
2018-08-28 20:17:29 -04:00

66 lines
1.5 KiB
Python

import requests
import json
import os
import sys
from selenium import webdriver
import datetime
from PIL import ImageFont
import inkyphat
def main():
fake_pages = {'2014': 7375, '2015': 23508, '2016': 17696, '2017': 19706, '2018': 9388}
#pages = print(get_goodreads_pages())
draw(fake_pages)
def get_goodreads_pages():
payload = {
'email': os.environ.get('EMAIL'),
'password': os.environ.get('PASSW'),
}
LOGIN_URL= 'https://www.goodreads.com/user/sign_in'
driver = webdriver.PhantomJS()
driver.get(LOGIN_URL)
username = driver.find_element_by_id('user_email')
password = driver.find_element_by_id('user_password')
username.send_keys(payload['email'])
password.send_keys(payload['password'])
form = driver.find_element_by_name('sign_in')
form.submit()
driver.get('https://www.goodreads.com/review/stats/24381583#pages')
stats = driver.execute_script('return page_stats')
return stats
def draw(pages):
colour = 'red'
inkyphat.set_colour(colour)
inkyphat.set_border(inkyphat.BLACK)
inkyphat.set_image("./background.png")
p2018 = str(pages['2018'])
#font = ImageFont.truetype(inkyphat.fonts.AmaticSCBold, 38)
#w, h = font.getsize(p2018)
## Center the text and align it with the name strip
#
#x = (inkyphat.WIDTH / 2) - (w / 2)
#y = 71 - (h / 2)
#
#inkyphat.text((x, y), p2018, inkyphat.BLACK, font)
#
## Partial update if using Inky pHAT display v1
inkyphat.show()
if __name__ == "__main__":
main()