www.netz39.de/tools/generate_freieshacken_events.py

62 lines
1.7 KiB
Python
Raw Normal View History

import os
import datetime
2023-11-09 13:23:10 +01:00
import sys
2023-11-09 12:41:00 +01:00
layout = "event"
title = "Freies Hacken"
event_description = f"""
**Wann: 19:30 Uhr**\\
**Wo: Netz39 e.V.**
2023-11-09 12:41:00 +01:00
Jeden Mittwoch treffen wir uns zum Basteln, Reparieren, Kochen und Ideen austauschen. Gäste sind gerne willkommen
Bitte beachtet, dass jede dritte Woche unser Stammtisch ist, wo wir über vereinsinterne Sachen reden und erst anschließend zum gemütlichen Abend übergehen.
2023-11-09 12:41:00 +01:00
"""
2023-11-09 13:01:20 +01:00
folder_name = "_events"
2023-11-09 12:41:00 +01:00
filename_prefix = "n39_freies_hacken"
# Function to generate the markdown content for a specific date
def generate_markdown_file(year, month, day):
markdown_content = f"""---
layout: {layout}
title: {title}
event_date: {year}-{month:02d}-{day:02d}
---
{event_description}
"""
2023-11-09 13:01:20 +01:00
folder_path = f"../{folder_name}/{year}/"
2023-11-09 12:41:00 +01:00
filename = f"{year}-{month:02d}-{day:02d}_{filename_prefix}.md"
file_path = os.path.join(folder_path, filename)
2023-11-09 13:01:20 +01:00
if not os.path.exists(folder_path):
os.makedirs(folder_path)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(markdown_content)
2023-11-09 13:01:20 +01:00
print(f"Markdown file '{filename}' generated successfully in the '{folder_path}' folder!")
2023-11-09 13:23:10 +01:00
if len(sys.argv) < 2:
print(f"Usage: python3 {sys.argv[0]} <year>")
sys.exit()
# Input year
2023-11-09 13:23:10 +01:00
year = int(sys.argv[1])
2023-11-09 12:02:18 +01:00
# Calculate Wednesdays
for month in range(1, 13):
for day in range(1, 32):
try:
# Generate a date object
2023-11-09 13:23:10 +01:00
current_date = datetime.date(year, month, day)
# Check if the date is a Wednesday
if current_date.weekday() == 2:
2023-11-09 13:23:10 +01:00
generate_markdown_file(year, month, day)
except ValueError:
# If the day is out of range for the month, skip to the next month
pass