improved readability, removed some unneeded variables and functions
This commit is contained in:
parent
6dce6b723d
commit
a46ca2bdb6
54
header.py
54
header.py
|
@ -1,51 +1,33 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
from bs4 import BeautifulSoup as bs
|
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class readHead():
|
class readHead():
|
||||||
inFile = ""
|
|
||||||
outHead = ""
|
outHead = ""
|
||||||
sTime = []
|
sTime = []
|
||||||
sTitle = ""
|
sTitle = ""
|
||||||
footStr = "\n</body>\n</html>"
|
|
||||||
|
|
||||||
def __init__(self, headerFile, sTitle):
|
def __init__(self, sTitle):
|
||||||
self.inFile = headerFile
|
|
||||||
self.sTitle = sTitle
|
self.sTitle = sTitle
|
||||||
self.outHead = ""
|
# self.outHead = ""
|
||||||
self.stime = []
|
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 UTC−06:00")) #TODO: I don't want to hard-code this but the %z utc offset isn't printing
|
|
||||||
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):
|
def __str__(self):
|
||||||
return(str(self.sed()))
|
return(str(self.genHead())) #TODO: pick css theme and append to output
|
||||||
|
|
||||||
|
# Start genHead()
|
||||||
|
def genHead(self):
|
||||||
|
|
||||||
|
# Generate html <head> element
|
||||||
|
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
|
||||||
|
|
||||||
|
headerStr = "<!DOCTYPE HTML>\n<html>\n<head>\n\t<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n\t<title>"
|
||||||
|
headerStr1 = "</title>\n\t<meta name=\"generator\" content=\"HTML.xonsh https://git.nixnet.services/amber/html.xonsh\"/>\n\t<meta name=\"created\" content=\""
|
||||||
|
headerStr2 = "\">\n\t<meta name=\"changed\" content=\""
|
||||||
|
headerStr3 = "\"/>\n</head>\n<body>\n\t"
|
||||||
|
|
||||||
def sed(self):
|
outHead = headerStr + str(self.sTitle) + headerStr1 + timeMod + headerStr2 + timeCreate + headerStr3
|
||||||
stdin = (str(self.read()))
|
return(outHead)
|
||||||
#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)
|
|
||||||
|
|
44
main.py
44
main.py
|
@ -24,42 +24,6 @@ def parseMd(inFile):
|
||||||
m2h = str(readFile.readMarkdown(inFile))
|
m2h = str(readFile.readMarkdown(inFile))
|
||||||
return(m2h)
|
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 = """\
|
|
||||||
#<!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():
|
def css():
|
||||||
print("placeholder")
|
print("placeholder")
|
||||||
|
|
||||||
|
@ -68,14 +32,8 @@ def main():
|
||||||
parseMd("sample.md")
|
parseMd("sample.md")
|
||||||
printHtml(headerStr, m2h, footStr, "outdir/index.html")
|
printHtml(headerStr, m2h, footStr, "outdir/index.html")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
#print(readFile.readMarkdown("/home/amber/website.sh/sample.md"))
|
print(str(header.readHead("string")) + str(parseMd("sample.md")) + footStr)
|
||||||
#print(parseMd("sample.md"))
|
|
||||||
|
|
||||||
#metadata("sample.md")
|
|
||||||
print(str(header.readHead("htmlTemplate/header.html", "string")))
|
|
||||||
|
|
||||||
#main()
|
#main()
|
||||||
test()
|
test()
|
||||||
|
|
Loading…
Reference in New Issue