zipping logs
This commit is contained in:
+5
-4
@@ -2,6 +2,7 @@ from typing import Union, List, Tuple
|
|||||||
import os
|
import os
|
||||||
import discord
|
import discord
|
||||||
import json
|
import json
|
||||||
|
import gzip
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -152,8 +153,8 @@ class GuildLogs:
|
|||||||
if os.path.exists(self.log_file):
|
if os.path.exists(self.log_file):
|
||||||
channels = {}
|
channels = {}
|
||||||
try:
|
try:
|
||||||
with open(self.log_file, mode="r") as f:
|
with open(self.log_file, mode="rb") as f:
|
||||||
channels = json.loads(f.readline().strip())
|
channels = json.loads(gzip.decompress(f.read()))
|
||||||
self.channels = {int(id): ChannelLogs(channels[id]) for id in channels}
|
self.channels = {int(id): ChannelLogs(channels[id]) for id in channels}
|
||||||
dt = (datetime.now() - t0).total_seconds()
|
dt = (datetime.now() - t0).total_seconds()
|
||||||
logging.info(f"log {self.guild.id} > loaded in {dt} s")
|
logging.info(f"log {self.guild.id} > loaded in {dt} s")
|
||||||
@@ -198,8 +199,8 @@ class GuildLogs:
|
|||||||
logging.info(f"log {self.guild.id} > queried in {dt} s -> {total_msg / dt} m/s")
|
logging.info(f"log {self.guild.id} > queried in {dt} s -> {total_msg / dt} m/s")
|
||||||
# write logs
|
# write logs
|
||||||
t0 = datetime.now()
|
t0 = datetime.now()
|
||||||
with open(self.log_file, mode="w") as f:
|
with open(self.log_file, mode="wb") as f:
|
||||||
f.write(json.dumps(self.dict()))
|
f.write(gzip.compress(bytes(json.dumps(self.dict()), "utf-8")))
|
||||||
dt = (datetime.now() - t0).total_seconds()
|
dt = (datetime.now() - t0).total_seconds()
|
||||||
logging.info(f"log {self.guild.id} > written in {dt} s")
|
logging.info(f"log {self.guild.id} > written in {dt} s")
|
||||||
return total_msg, total_chan
|
return total_msg, total_chan
|
||||||
|
|||||||
Reference in New Issue
Block a user