Skip to content

Instantly share code, notes, and snippets.

@masouduut94
Last active July 10, 2020 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masouduut94/88ce1859514b820495649387b42e3ec5 to your computer and use it in GitHub Desktop.
Save masouduut94/88ce1859514b820495649387b42e3ec5 to your computer and use it in GitHub Desktop.
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