almost done

This commit is contained in:
Tyrel Souza 2018-08-28 21:03:11 -04:00
parent 972af411e9
commit 5fc486ec39

64
good.py
View File

@ -7,14 +7,18 @@ import datetime
from PIL import ImageFont
import inkyphat
FAKE = True
def main():
fake_pages = {'2014': 7375, '2015': 23508, '2016': 17696, '2017': 19706, '2018': 9388}
#pages = print(get_goodreads_pages())
draw(fake_pages)
pages = {'2014': 7375, '2015': 23508, '2016': 17696, '2017': 19706, '2018': 9388}
books = {"2018":33,"2017":64,"2016":47,"2015":75,"2014":19}
if not FAKE:
pages, books = get_goodreads_stats()
stats = get_stats(pages, books)
draw(stats)
def get_goodreads_pages():
def get_goodreads_stats():
payload = {
'email': os.environ.get('EMAIL'),
'password': os.environ.get('PASSW'),
@ -35,31 +39,49 @@ def get_goodreads_pages():
form.submit()
driver.get('https://www.goodreads.com/review/stats/24381583#pages')
stats = driver.execute_script('return page_stats')
return stats
pages = driver.execute_script('return page_stats')
books = driver.execute_script('return year_stats')
return pages, books
def draw(pages):
def get_stats(pages, books):
coords = {
"year": [
(55, 17),(109,17),(163,17)
],
"books": [
(55, 45),(109,45),(163,45)
],
"pages": [
(55, 75),(109,75),(163,75)
],
}
_stats = []
for idx, year in enumerate(list(reversed(sorted(books.keys())))[:3]):
page_count = pages[year]
book_count = books[year]
_stats.append({
'year': [str(year), coords['year'][idx]],
'books': [str(book_count), coords['books'][idx]],
'pages': [str(page_count), coords['pages'][idx]],
})
return _stats
def draw(stats):
colour = 'red'
inkyphat.set_colour(colour)
inkyphat.set_border(inkyphat.BLACK)
inkyphat.set_border(inkyphat.RED)
inkyphat.set_image("./background.png")
p2018 = str(pages['2018'])
font = ImageFont.truetype(inkyphat.fonts.AmaticSCBold, 18)
#font = ImageFont.truetype(inkyphat.fonts.AmaticSCBold, 38)
#w, h = font.getsize(p2018)
for column in ('year', 'books', 'pages'):
for year in stats:
count = year[column][0]
x,y = year[column][1]
w, h = font.getsize(count)
inkyphat.text((x, y), count, inkyphat.BLACK, font)
## 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()