sorta works, flips html stuff around

This commit is contained in:
Amber 2022-03-05 01:04:26 -06:00
parent b5e1841885
commit 6dce6b723d
3 changed files with 71 additions and 46 deletions

View File

@ -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</body>\n</html>"
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</body>\n</html>"
def getTime(self):
gettime = datetime.datetime.now()
modDate = str(gettime.strftime("%A, %B %d, %Y at %X UTC06: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)

View File

@ -7,3 +7,6 @@
<meta name="created" content="CREATEDATE"/>
<meta name="changed" content="MODDATE"/>
</head>
<body>
</body>
</html>

72
main.py
View File

@ -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 UTC06: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 = """\
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>"""
headerStr1 = """</title>
<meta name="generator" content="HTML.xonsh https://git.nixnet.services/amber/html.xonsh"/>
<meta name="created" content=" """
headerStr2 = """"/>
<meta name="changed" content=" """
headerStr3 = """"/>
</head>
<body>
"""
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 UTC06: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 = """\
#<!DOCTYPE HTML>
#<html>
#<head>
# <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
# <title>"""
# headerStr1 = """</title>
# <meta name="generator" content="HTML.xonsh https://git.nixnet.services/amber/html.xonsh"/>
# <meta name="created" content=" """
# headerStr2 = """"/>
# <meta name="changed" content=" """
# headerStr3 = """"/>
#</head>
#<body>
#"""
#
# 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()