Skip to content

Instantly share code, notes, and snippets.

@salvatorecapolupo
Created January 11, 2026 11:05
Show Gist options
  • Select an option

  • Save salvatorecapolupo/4d2bd9fe8079f5d61310ba9e50bc738a to your computer and use it in GitHub Desktop.

Select an option

Save salvatorecapolupo/4d2bd9fe8079f5d61310ba9e50bc738a to your computer and use it in GitHub Desktop.
Genera un pdf del calendario del mese corrente, in formato griglia, stampabile senza sprechi di inchiostro e con spazio per scrivere nei giorni.
import calendar
import locale
from datetime import datetime
from reportlab.lib.pagesizes import A4
from reportlab.lib.colors import HexColor
from reportlab.pdfgen import canvas
from reportlab.lib.units import cm
# =========================
# CONFIGURAZIONE
# =========================
CONFIG = {
"lingua": "it_IT.UTF-8",
# Palette eco / low-ink
"bg_color": "#FFFFFF",
"grid_color": "#444444",
"text_color": "#111111",
"accent_color": "#008B8B", # cyberpunk sobrio (verde/blu scuro)
"font_title_size": 32,
"font_day_size": 12,
"font_date_size": 16,
}
# =========================
# FUNZIONE PRINCIPALE
# =========================
def genera_calendario_cyberpunk_green():
locale.setlocale(locale.LC_TIME, CONFIG["lingua"])
now = datetime.now()
year = now.year
month = now.month
month_name = now.strftime("%B").upper()
filename = f"calendario_{year}_{month:02d}_cyberpunk_green.pdf"
cal = calendar.monthcalendar(year, month)
c = canvas.Canvas(filename, pagesize=A4)
width, height = A4
# Colori
bg = HexColor(CONFIG["bg_color"])
grid = HexColor(CONFIG["grid_color"])
text = HexColor(CONFIG["text_color"])
accent = HexColor(CONFIG["accent_color"])
# Sfondo (bianco)
c.setFillColor(bg)
c.rect(0, 0, width, height, stroke=0, fill=1)
# Titolo
c.setFillColor(accent)
c.setFont("Helvetica-Bold", CONFIG["font_title_size"])
c.drawCentredString(width / 2, height - 2.5 * cm, f"{month_name} {year}")
# Griglia
start_x = 2 * cm
start_y = height - 5 * cm
cell_w = (width - 4 * cm) / 7
cell_h = 2.2 * cm
giorni = ["LUN", "MAR", "MER", "GIO", "VEN", "SAB", "DOM"]
# Intestazione giorni
c.setFont("Helvetica-Bold", CONFIG["font_day_size"])
for i, g in enumerate(giorni):
c.setFillColor(accent if g in ["SAB", "DOM"] else text)
c.drawCentredString(
start_x + i * cell_w + cell_w / 2,
start_y,
g
)
# Celle calendario
c.setFont("Helvetica", CONFIG["font_date_size"])
c.setLineWidth(0.6)
for row, week in enumerate(cal):
for col, day in enumerate(week):
x = start_x + col * cell_w
y = start_y - (row + 1) * cell_h
# Bordo cella (linea sottile)
c.setStrokeColor(grid)
c.rect(x, y, cell_w, cell_h, stroke=1, fill=0)
if day != 0:
is_weekend = col >= 5
c.setFillColor(accent if is_weekend else text)
c.drawRightString(
x + cell_w - 6,
y + cell_h - 18,
str(day)
)
# Firma minimale stile terminal
c.setFont("Courier", 8)
c.setFillColor(grid)
c.drawRightString(
width - 1.5 * cm,
1.2 * cm,
">> CYBERCAL // ECO MODE"
)
c.save()
print(f"PDF generato: {filename}")
# =========================
# ESECUZIONE
# =========================
if __name__ == "__main__":
genera_calendario_cyberpunk_green()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment