def saveFile(self):
self.settings['lastFile'] = filedialog.asksaveasfilename(filetypes=[('JSON file', '.json'), ('All files', '*')], initialfile=self.settings['lastFile'])
id = os.path.basename(self.settings['lastFile'])
id = id.split('.')[0]
# Return if file name was not chosen (user closed the dialog)
if (len(id) < 1):
return
with open(os.path.join(os.getcwd(), 'settings.json'), mode='w') as file:
file.write(json.dumps(self.settings))
try:
with open(os.path.join(os.getcwd(), 'data', (str(id).lower() + '.json')), mode='w') as file:
file.write(json.dumps(self.output))
except:
return
if (not (id in self.accountlist)):
self.accountlist[id] = dict()
try:
with open(os.path.join(os.getcwd(), 'data', (str(id).lower() + '.0.json')), mode='r') as file:
self.accountlist[id]['start'] = json.loads(file.read())['timestamp']
except:
with open(os.path.join(os.getcwd(), 'data', (str(id).lower() + '.0.json')), mode='w') as file:
self.output['timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d<br>%H:%M:%S")
file.write(json.dumps(self.output))
self.accountlist[id]['start'] = self.output['timestamp']
self.accountlist[id]['id'] = id
self.accountlist[id]['filename'] = self.settings['lastFile']
self.accountlist[id]['stop'] = self.output['timestamp']
try:
self.accountlist[id]['odometer'] = self.data.current['truck']['odometer']
except:
self.accountlist[id]['odometer'] = 0
self.accountlist[id]['distance'] = self.output['totalDistanceDriven']
self.accountlist[id]['totalFuel'] = self.output['fuelUsed']
self.accountlist[id]['averageFuel'] = self.output['averageFuelConsumption']
self.accountlist[id]['averageSpeed'] = self.output['averageSpeed']
self.accountlist[id]['rating'] = 'N/A' #TODO: Make rating system
with open(os.path.join(os.getcwd(), 'data', ('accountlist.json')), mode='w') as file:
file.write(json.dumps(self.accountlist))
telematics.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录