Last active
July 10, 2020 08:40
-
-
Save masouduut94/88ce1859514b820495649387b42e3ec5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from os import makedirs | |
from os.path import exists, join | |
from bunch import bunchify | |
from datetime import datetime | |
class JsonMeta(object): | |
HOURS = 4 | |
MINUTES = 59 | |
SECONDS = 59 | |
PATH_TO_SAVE = 'jsons' | |
class JsonParser: | |
# .... | |
# I did not include the rest of code to let you | |
# just find the update to code | |
def json_output(self, output_name): | |
if not output_name.endswith('.json'): | |
output_name += '.json' | |
with open(output_name, 'w') as file: | |
json.dump(self.output(), file) | |
def set_start(self): | |
self.start_time = datetime.now() | |
def schedule_output(self, output_path=JsonMeta.PATH_TO_SAVE, hours: int = 0, minutes: int = 0, seconds: int = 60): | |
end = datetime.now() | |
interval = 0 | |
interval += min([hours, JsonMeta.HOURS]) * 3600 | |
interval += min([minutes, JsonMeta.MINUTES]) * 60 | |
interval += min([seconds, JsonMeta.SECONDS]) | |
diff = (end - self.start_time).seconds | |
if diff > interval: | |
output_name = self.start_time.strftime('%Y-%m-%d %H-%M-%S') + '.json' | |
output = join(output_path, output_name) | |
if not exists(output_path): | |
makedirs(output_path) | |
self.json_output(output_name=output) | |
self.frames.clear() | |
self.start_time = datetime.now() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment