html.xonsh/header.py

52 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/python
2022-03-05 07:04:26 +00:00
from bs4 import BeautifulSoup as bs
import datetime
2022-03-05 07:04:26 +00:00
import re
2022-03-05 04:41:12 +00:00
class readHead():
inFile = ""
outHead = ""
2022-03-05 07:04:26 +00:00
sTime = []
sTitle = ""
footStr = "\n</body>\n</html>"
2022-03-05 07:04:26 +00:00
def __init__(self, headerFile, sTitle):
self.inFile = headerFile
2022-03-05 07:04:26 +00:00
self.sTitle = sTitle
self.outHead = ""
2022-03-05 07:04:26 +00:00
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
2022-03-05 07:04:26 +00:00
createDate = modDate #TODO: make this seperate
global sTime
self.sTime.append(str(modDate))
self.sTime.append(str(createDate))
return(self.sTime)
2022-03-05 07:04:26 +00:00
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)