four columns

This commit is contained in:
Tyrel Souza 2018-08-28 21:43:18 -04:00
parent c1e0f8bbaf
commit 9e44323cac

37
good.py
View File

@ -1,9 +1,10 @@
import datetime
import requests import requests
import json import json
import os import os
import sys import sys
from selenium import webdriver from selenium import webdriver
import datetime from collections import defaultdict
from PIL import ImageFont from PIL import ImageFont
import inkyphat import inkyphat
@ -44,19 +45,23 @@ def get_goodreads_stats():
return pages, books return pages, books
def get_stats(pages, books): def get_stats(pages, books):
coords = { size = 4
"year": [ col_w, col_h = 40, 32
(53, 17),(107,17),(161,17) x_start, y_start = 53, 10
], row_offsets = [0,5,0]
"books": [
(53, 45),(107,45),(161,45) rows = ["year", "books", "pages"]
], coords = defaultdict(list)
"pages": [
(53, 75),(107,75),(161,75) 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 = [] _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] page_count = pages[year]
book_count = books[year] book_count = books[year]
_stats.append({ _stats.append({
@ -73,8 +78,8 @@ def draw(stats):
inkyphat.set_image("./background.png") inkyphat.set_image("./background.png")
draw_row('year', stats, 12) draw_row('year', stats, 12)
draw_row('books', stats, 14) draw_row('books', stats, 18)
draw_row('pages', stats, 10) draw_row('pages', stats, 12)
inkyphat.show() inkyphat.show()
@ -86,7 +91,7 @@ def draw_row(row, stats, size):
count = year[row][0] count = year[row][0]
x,y = year[row][1] x,y = year[row][1]
w, h = font.getsize(count) w, h = font.getsize(count)
inkyphat.text((x, y), count, inkyphat.BLACK, font) inkyphat.text((x, y), count, inkyphat.RED, font)
if __name__ == "__main__": if __name__ == "__main__":
main() main()