From 6dce6b723dc55161d62433c2a46c8b62c9195d0a Mon Sep 17 00:00:00 2001 From: Amber Date: Sat, 5 Mar 2022 01:04:26 -0600 Subject: [PATCH] sorta works, flips html stuff around --- header.py | 40 +++++++++++++++++----- htmlTemplate/header.html | 3 ++ main.py | 74 ++++++++++++++++++++-------------------- 3 files changed, 71 insertions(+), 46 deletions(-) diff --git a/header.py b/header.py index 1da9377..67a8dd0 100755 --- a/header.py +++ b/header.py @@ -1,29 +1,51 @@ #!/usr/bin/python -import bs4 +from bs4 import BeautifulSoup as bs import datetime +import re class readHead(): inFile = "" outHead = "" - time = [] + sTime = [] sTitle = "" footStr = "\n\n" - def __init__(self, headerFile, title): + def __init__(self, headerFile, sTitle): self.inFile = headerFile - self.sTitle = title + self.sTitle = sTitle self.outHead = "" - self.time = [] + self.stime = [] self.footStr = "\n\n" def getTime(self): gettime = datetime.datetime.now() modDate = str(gettime.strftime("%A, %B %d, %Y at %X UTC−06:00")) #TODO: I don't want to hard-code this but the %z utc offset isn't printing - createDate = self.modDate #TODO: make this seperate - global time - time.append(str(modDate)) - time.append(str.createDate) + createDate = modDate #TODO: make this seperate + global sTime + self.sTime.append(str(modDate)) + self.sTime.append(str(createDate)) + return(self.sTime) + def read(self): + file = open(self.inFile, "r") + headStr = file.read() + file.close() + return(headStr) + + def __str__(self): + return(str(self.sed())) + + def sed(self): + stdin = (str(self.read())) + #soupSed = soup(stdin, "lxml") + self.getTime() + stdin = str(re.sub("CREATEDATE", str(self.sTime[0]), stdin)) + stdin = str(re.sub("MODDATE", str(self.sTime[1]), stdin)) + + soup = bs(stdin, "lxml") + soup.head.title = str(self.sTitle) + + return(soup) diff --git a/htmlTemplate/header.html b/htmlTemplate/header.html index 5fdebdc..338fa10 100644 --- a/htmlTemplate/header.html +++ b/htmlTemplate/header.html @@ -7,3 +7,6 @@ + + + diff --git a/main.py b/main.py index ce58eb6..5ff442d 100755 --- a/main.py +++ b/main.py @@ -24,47 +24,47 @@ def parseMd(inFile): m2h = str(readFile.readMarkdown(inFile)) return(m2h) -def metadata(inFile): - # Read metadata from possible file - ## Pretend there's code here - - # Generate metadata - getTime = datetime.datetime.now() - timeMod = str(getTime.strftime("%A, %B %d, %Y at %X UTC−06:00")) #TODO: I don't want to hard-code this but the %z utc offset isn't printing - timeCreate = timeMod - - title = inFile.split(".") - title = str(title[0]) #TODO: figure out a way to make longer titles without putting spaces in the filename - # Take title as optional command-line arguement - - # Generate html - global headerStr - headerStr = """\ - - - - - """ - headerStr1 = """ - - - - - -""" - - headerStr = headerStr + str(title) + headerStr1 + timeMod + headerStr2 + timeCreate + headerStr3 - - return(str(headerStr)) +#def metadata(inFile): +# # Read metadata from possible file +# ## Pretend there's code here +# +# # Generate metadata +# getTime = datetime.datetime.now() +# timeMod = str(getTime.strftime("%A, %B %d, %Y at %X UTC−06:00")) #TODO: I don't want to hard-code this but the %z utc offset isn't printing +# timeCreate = timeMod +# +# title = inFile.split(".") +# title = str(title[0]) #TODO: figure out a way to make longer titles without putting spaces in the filename +# # Take title as optional command-line arguement +# +# # Generate html +# global headerStr +# headerStr = """\ +# +# +# +# +# """ +# headerStr1 = """ +# +# +# +# +# +#""" +# +# headerStr = headerStr + str(title) + headerStr1 + timeMod + headerStr2 + timeCreate + headerStr3 +# +# return(str(headerStr)) def css(): print("placeholder") def main(): - metadata("sample.md") +# metadata("sample.md") parseMd("sample.md") printHtml(headerStr, m2h, footStr, "outdir/index.html") @@ -75,7 +75,7 @@ def test(): #print(parseMd("sample.md")) #metadata("sample.md") - header.readHead("htmlTemplate/header.header.html", "string") + print(str(header.readHead("htmlTemplate/header.html", "string"))) #main() -test() \ No newline at end of file +test()