55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
import blogs
|
|
import header
|
|
import root
|
|
from datetime import datetime
|
|
|
|
url = "https://deadvey.com"
|
|
blog_index_path = f"{root.path}/blog/index.html"
|
|
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}.html"
|
|
|
|
# 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}<br/><a href='/rss'>RSS Feed</a>")
|
|
|
|
if previous_year != year:
|
|
blog_index_file.write(f"<h2>{year}:</h2>")
|
|
|
|
# Write the link to the page
|
|
blog_index_file.write(f"{day}: <a href='{url}/{blog_file_path}'>{blogs.blogs_array[current_blog][0]}</a><br/>")
|
|
|
|
# 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]}
|
|
<i>Published: {day}/{year} at {second_of_the_day}</i>
|
|
</pre>
|
|
<style>
|
|
pre \u007b
|
|
white-space: pre-wrap;
|
|
\u007d
|
|
</style>
|
|
'''
|
|
current_blog_file.write(content)
|
|
|
|
previous_year = year
|
|
blog_index_file.write("</pre>")
|
|
|