51 lines
962 B
Python
Executable File
51 lines
962 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
from datetime import datetime
|
|
|
|
# Get the current date and time
|
|
now = datetime.now()
|
|
year = now.strftime("%Y")
|
|
month = now.strftime("%m")
|
|
day = now.strftime("%d")
|
|
time_str = now.strftime("%H:%M")
|
|
time_str_sec = now.strftime("%H%M%S")
|
|
|
|
|
|
|
|
if str(day).endswith("1"): suffix = "st"
|
|
elif str(day).endswith("2"): suffix = "nd"
|
|
elif str(day).endswith("3"): suffix = "rd"
|
|
else: suffix = "th"
|
|
|
|
|
|
|
|
# Create the directory structure
|
|
directory = os.path.join("content", year, month, day)
|
|
os.makedirs(directory, exist_ok=True)
|
|
|
|
# Define the filename
|
|
filename = f"blog-entry-{time_str_sec}.md"
|
|
file_path = os.path.join(directory, filename)
|
|
|
|
print(file_path)
|
|
|
|
|
|
HEADER = f'''title:
|
|
description:
|
|
tags:
|
|
date: {year}-{month}-{day} {time_str}
|
|
|
|
# Blog Entry
|
|
|
|
'''
|
|
|
|
|
|
# Create the Markdown file and write the header
|
|
with open(file_path, 'a+') as file:
|
|
header = HEADER
|
|
file.write(header)
|
|
file.close()
|
|
|
|
print(f"Blog entry created: {file_path}")
|