telematics.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:ets2-telemetry-client-python 作者: roundowl 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号