Created
July 28, 2020 14:19
-
-
Save yfwu/104607893263f1034baf04bccfd2c1a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from bs4 import BeautifulSoup | |
def get_metadata(f): | |
with open(f, 'rb') as h: | |
html_doc = h.read() | |
soup = BeautifulSoup(html_doc, 'html.parser') | |
title = str(soup.find("title")).replace("<title>", "").replace("</title>", "") | |
date = soup.find("meta", property="created") | |
return title, date | |
b = sys.argv[1] # base | |
entries = [f for f in os.listdir(b) if os.path.isfile(os.path.join(b, f))] | |
# entries.sort(key=lambda x: os.stat(os.path.join(b, x)).st_mtime) | |
entries.remove('index.html') | |
entries.remove('.DS_Store') | |
with open('index.html', 'w') as index: | |
head = open(b + '/source/head.html', 'r') | |
index.write(head.read()) | |
head.close() | |
for entry in entries: | |
title, date = get_metadata(entry) | |
new_enteires = "<a href='" + entry + "'>" + title + "</a>" | |
print(date) | |
index.write(new_enteires) | |
index.write("<br>") | |
tail = open(b + '/source/tail.html', 'r') | |
index.write(tail.read()) | |
tail.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment