💾 Archived View for breadpunk.club › ~flatbread › glog › glog.py captured on 2022-07-16 at 14:23:40.

View Raw

More Information

⬅️ Previous capture (2021-12-03)

-=-=-=-=-=-=-

#!/usr/bin/env python3
import os
import subprocess
import datetime

page = '''# ~flatbread's glog
## updated whenever I feel like it

'''

pageEnd = '''
=> .. back to main page'''

articles = []
for filename in os.listdir("/home/flatbread/public_gemini/glog/"):
    print("Processing file %s"%filename)
    if (filename[-4:] == ".gmi" and filename != "index.gmi"):
        splits = filename.split("-", 3)
        articles.append((filename,datetime.date(int(splits[0]),int(splits[1]),int(splits[2]))))

# list.sort is done in place, so I can simply sort by day, then month, then year
articles.sort(key=lambda a : a[1].day, reverse=True)
articles.sort(key=lambda a : a[1].month, reverse=True)
articles.sort(key=lambda a : a[1].year, reverse=True)

for article in articles:
    page += "=> %s %s"%(article[0], str(article[1].year) + '-' + str(article[1].month).zfill(2) + '-' + str(article[1].day).zfill(2) + open(article[0]).readline()[1:])

page += pageEnd

print()
print("Page generated, saving to index.gmi")
print("-----------------------------------")
print(page)

outputfile = open("index.gmi", "w")
outputfile.write(page)
outputfile.close
print("-----------------------------------")
print("Send update request to antenna? Y/N")
if input().lower() == "y":
    os.system("bombadillo gemini://warmedal.se/~antenna/submit?gemini:%2F%2Fbreadpunk.club%2F~flatbread%2Fglog%2Findex.gmi")