#!/usr/bin/env python3 # création d'un calendrier mensuel, sous forme de fichier SVG # 7 colonnes (L, M, M, J, V, S, D) avec entête x 6 lignes # utilisation : # python3 calendrier.py nombre-de-jours-du-mois 1er-jour-du-mois # python3 calendrier.py 31 jeudi # le script demandera comment nommer le fichier SVG # le but final est d'appliquer une police «Hershey» dans inkscape pour que le calendrier # puisse être réalisé au plotter # # 23/12/2025 pierre@lesporteslogiques.net # Debian 12 @ tenko, python 3.11.2 import sys # Colonnes du calendrier JOURS = ["L", "M", "M", "J", "V", "S", "D"] JOUR_INDEX = { "lundi": 0, "mardi": 1, "mercredi": 2, "jeudi": 3, "vendredi": 4, "samedi": 5, "dimanche": 6, } def generate_calendar_svg(nb_days, first_day, filename): if first_day not in JOUR_INDEX: raise ValueError("Jour invalide.") start_col = JOUR_INDEX[first_day] # Dimensions cols = 7 rows = 6 cell_width = 30 cell_height = 22 header_height = 36 width = cols * cell_width height = header_height + rows * cell_height # Taille maximale des chiffres day_font_size = int(cell_height * 0.6) svg = [] svg.append(f'') svg.append('') # En-têtes for col, label in enumerate(JOURS): x = col * cell_widthc helloworld.txt svg.append( f'{label}' ) # Placement des jours day = 1 for cell in range(start_col, start_col + nb_days): row = cell // cols col = cell % cols x = col * cell_width + cell_width / 2 y = header_height + row * cell_height + cell_height / 2 + day_font_size / 3 svg.append( f'{day}' ) day += 1 svg.append("") with open(filename, "w", encoding="utf-8") as f: f.write("\n".join(svg)) if __name__ == "__main__": if len(sys.argv) != 3: print("Usage : python3 calendrier.py ") sys.exit(1) nb_jours = int(sys.argv[1]) jour_1er = sys.argv[2].lower() filename = input("Nom du fichier SVG à créer (ex: calendrier.svg) : ").strip() if not filename.endswith(".svg"): filename += ".svg" generate_calendar_svg(nb_jours, jour_1er, filename) print(f"Fichier '{filename}' généré.")