48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
import blogs
|
|
import header
|
|
import root
|
|
from datetime import datetime
|
|
|
|
url = "mttp://deadvey.com"
|
|
blog_index_path = f"{root.path}/blog/index.md"
|
|
previous_year = 0 # Set the previous year as 0, the year is outputted to the page if it is different to 'previous_year'
|
|
|
|
# Open the blog index (/blog/index.md)
|
|
with open(blog_index_path, "w") as blog_index_file:
|
|
# Loop over every blog post
|
|
for current_blog in range(len(blogs.blogs_array)-1, 0, -1): # eg 50 - 0
|
|
blog_file_path = f"/blog/{current_blog}.md"
|
|
|
|
# Hexadecimal time parsing/formatting
|
|
parsed_date = datetime.strptime(blogs.blogs_array[current_blog][2], '%a, %d %b %Y %H:%M:%S')
|
|
|
|
year = str(hex(int(parsed_date.strftime('%Y'))))[2:]
|
|
day = str(hex(int(parsed_date.timetuple().tm_yday)))[2:]
|
|
|
|
hour = int(parsed_date.strftime('%H'))
|
|
minute = int(parsed_date.strftime('%M'))
|
|
second = int(parsed_date.strftime('%S'))
|
|
second_of_the_day = str(hex(int(((hour * 3600) + (minute * 60) + second) * (65536/86400))))[2:]
|
|
|
|
if current_blog == len(blogs.blogs_array)-1:
|
|
blog_index_file.write(f"{header.header}\n[RSS Feed](/rss)\n")
|
|
|
|
if previous_year != year:
|
|
blog_index_file.write(f"**{year}:**\n")
|
|
|
|
# Write the link to the page
|
|
blog_index_file.write(f"{day}: [{blogs.blogs_array[current_blog][0]}]({url}/{blog_file_path})\n")
|
|
|
|
# Also write all the blogs to their respective pages
|
|
with open(f"{root.path}{blog_file_path}","w") as current_blog_file:
|
|
content = f'''
|
|
{header.header}
|
|
{blogs.blogs_array[current_blog][0]}:
|
|
{blogs.blogs_array[current_blog][1]}
|
|
_Published: {day}/{year} at {second_of_the_day})_
|
|
'''
|
|
current_blog_file.write(content)
|
|
|
|
previous_year = year
|
|
|