-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTask.py
More file actions
36 lines (27 loc) · 901 Bytes
/
Task.py
File metadata and controls
36 lines (27 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
import json , os
class Task:
def __init__(self , taskBasePath):
self.taskBasePath = taskBasePath
self.taskData = {}
if os.path.exists(self.taskBasePath + '.json'):
with open(self.taskBasePath + '.json') as jsonFile:
self.taskData = json.load(jsonFile)
else:
self.taskData['tests'] = []
def getData(self):
return self.taskData
def getTests(self):
return self.taskData['tests']
def addTask(self , input , output = ""):
toRemove = None
for test in self.taskData['tests']:
if test['input'].strip() == input.strip():
if test['output'].strip() == output.strip():
return
toRemove = test
if toRemove:
self.taskData['tests'].remove(toRemove)
self.taskData['tests'].append({'input' : input , 'output':output})
with open(self.taskBasePath + '.json' , 'wb') as jsonFile:
jsonFile.write(json.dumps(self.taskData).encode())