notebookvb
This commit is contained in:
@@ -76,6 +76,39 @@ def draw_sudoku(c: Canvas, x0: float, y0: float, cell: float,
|
||||
c.line(x0 + i * cell, y0, x0 + i * cell, y0 - 9 * cell)
|
||||
|
||||
|
||||
def generate_pdf(puzzles: list[dict], output_path: Path):
|
||||
"""puzzles: difficulty, puzzle, solution, puzzle_date"""
|
||||
BOARD_CM = 11
|
||||
SOL_CM = 6
|
||||
GAP = 1.5 * cm
|
||||
page_w, page_h = A4
|
||||
|
||||
c = Canvas(str(output_path), pagesize=A4)
|
||||
|
||||
for i in range(0, len(puzzles), 2):
|
||||
for j, p in enumerate(puzzles[i:i + 2]):
|
||||
cell = BOARD_CM * cm / 9
|
||||
board = 9 * cell
|
||||
x0 = (page_w - board) / 2
|
||||
y0 = page_h - 2 * cm - j * (BOARD_CM * cm + 3 * cm)
|
||||
draw_sudoku(c, x0, y0, cell, p["puzzle"],
|
||||
f"Sudoku {p['difficulty'].capitalize()} — {p['puzzle_date']}")
|
||||
c.showPage()
|
||||
|
||||
c.setFont("ArialBold", 14)
|
||||
c.drawCentredString(page_w / 2, page_h - 2 * cm, "Řešení")
|
||||
y_cursor = page_h - 3.5 * cm
|
||||
for p in puzzles:
|
||||
sol_cell = SOL_CM * cm / 9
|
||||
sol_board = 9 * sol_cell
|
||||
x0 = (page_w - sol_board) / 2
|
||||
draw_sudoku(c, x0, y_cursor, sol_cell, p["puzzle"],
|
||||
p["difficulty"].capitalize(), show_solution=True, solution=p["solution"])
|
||||
y_cursor -= sol_board + GAP
|
||||
c.showPage()
|
||||
c.save()
|
||||
|
||||
|
||||
def main():
|
||||
conn = connect_mysql(database="puzzle")
|
||||
cur = conn.cursor()
|
||||
|
||||
Reference in New Issue
Block a user