goodread-phat/good.py

66 lines
1.5 KiB
Python
Raw Normal View History

2018-08-28 22:44:44 +00:00
import requests
import json
import os
2018-08-29 00:17:29 +00:00
import sys
2018-08-28 22:44:44 +00:00
from selenium import webdriver
import datetime
2018-08-29 00:17:29 +00:00
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)
2018-08-28 22:44:44 +00:00
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
2018-08-29 00:17:29 +00:00
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()
2018-08-28 22:44:44 +00:00
if __name__ == "__main__":
main()
2018-08-29 00:17:29 +00:00