html.xonsh/header.py

52 lines
1.3 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python
from bs4 import BeautifulSoup as bs
import datetime
import re
class readHead():
inFile = ""
outHead = ""
sTime = []
sTitle = ""
footStr = "\n</body>\n</html>"
def __init__(self, headerFile, sTitle):
self.inFile = headerFile
self.sTitle = sTitle
self.outHead = ""
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 = 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)