yuuki/libs/data.py

34 lines
973 B
Python
Raw Normal View History

2019-08-22 18:33:10 +08:00
#!/usr/bin/python3
# coding=UTF-8
2019-08-24 14:43:16 +08:00
import os, time
2019-08-22 18:33:10 +08:00
class Yuuki_Data:
def __init__(self):
2019-08-24 14:43:16 +08:00
self.LogType = {
"JoinGroup":"<li>%s: %s(%s) -> Inviter: %s</li>"
}
self.LogPath = "logs/"
self.LogName = "{}.html"
self.initHeader = "<title>{} - SYB</title>" \
"<meta charset='utf-8' />"
for Type in self.LogType:
name = self.LogPath + self.LogName.format(Type)
2019-08-24 15:02:26 +08:00
if not os.path.isfile(name):
2019-08-24 14:43:16 +08:00
with open(name, "w") as f:
f.write(self.initHeader.format(Type))
def logFile(self, Type, Mode):
return open(self.LogPath + self.LogName.format(Type), Mode)
def updateLog(self, Type, Data):
with self.logFile(Type, "a") as f:
f.write(self.LogType[Type] % Data)
def getTime(self, format="%b %d %Y %H:%M:%S %Z"):
Time = time.localtime(time.time())
return time.strftime(format, Time)