diff --git a/good.py b/good.py index 45140e6..886c254 100644 --- a/good.py +++ b/good.py @@ -1,9 +1,10 @@ +import datetime import requests import json import os import sys from selenium import webdriver -import datetime +from collections import defaultdict from PIL import ImageFont import inkyphat @@ -44,19 +45,23 @@ def get_goodreads_stats(): return pages, books def get_stats(pages, books): - coords = { - "year": [ - (53, 17),(107,17),(161,17) - ], - "books": [ - (53, 45),(107,45),(161,45) - ], - "pages": [ - (53, 75),(107,75),(161,75) - ], - } + size = 4 + col_w, col_h = 40, 32 + x_start, y_start = 53, 10 + row_offsets = [0,5,0] + + rows = ["year", "books", "pages"] + coords = defaultdict(list) + + for column in range(0, size): + for row in range(0, len(rows)): + coords[rows[row]].append([ + row_offsets[row] + x_start + (column*col_w), + y_start + (row*col_h), + ]) + _stats = [] - for idx, year in enumerate(list(reversed(sorted(books.keys())))[:3]): + for idx, year in enumerate(list(reversed(sorted(books.keys())))[:size]): page_count = pages[year] book_count = books[year] _stats.append({ @@ -73,8 +78,8 @@ def draw(stats): inkyphat.set_image("./background.png") draw_row('year', stats, 12) - draw_row('books', stats, 14) - draw_row('pages', stats, 10) + draw_row('books', stats, 18) + draw_row('pages', stats, 12) inkyphat.show() @@ -86,7 +91,7 @@ def draw_row(row, stats, size): count = year[row][0] x,y = year[row][1] w, h = font.getsize(count) - inkyphat.text((x, y), count, inkyphat.BLACK, font) + inkyphat.text((x, y), count, inkyphat.RED, font) if __name__ == "__main__": main()