Using own time string-format for old Python compat

This commit is contained in:
Fierelier 2020-11-24 16:45:29 +01:00
parent c22f7aa3c2
commit 05bd0764e2
1 changed files with 10 additions and 6 deletions

View File

@ -29,6 +29,7 @@ import asyncio
import logging
import configparser
import datetime
import json
distro = "Discord but fast"
version = (0,1,0)
versionString = ".".join(map(str,version))
@ -472,22 +473,25 @@ class guiChannel:
def setReady(self):
self.ready = True
def dtToString(dt):
return json.dumps([dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,dt.microsecond])
def dtFromString(js):
ls = json.loads(js)
return datetime.datetime(*ls)
def getMessageTimePath(channel):
return p(loginPath,"messageTimes",str(channel.id))
def getLastMessageTime(channel):
mtpath = getMessageTimePath(channel)
if not os.path.isfile(mtpath): return None
try:
return datetime.fromisoformat(open(mtpath,"r").read())
except:
print("reading old time failed, ditching")
return None
return dtFromString(open(mtpath,"r").read())
def setLastMessageTime(channel,time):
mtpath = getMessageTimePath(channel)
fh = open(mtpath,"w")
fh.write(time.isoformat())
fh.write(dtToString(time))
fh.close()
def discordClient(token):