import json
# data = dict(
# total_pulps=0,
# total_carts=0,
# average_pulp=0,
# last_record=0,
# day_count=0,
# night_count=0,
# total_day_count=0,
# total_night_count=0
# )
#
# with open('work_record.json', 'w') as f:
# json.dump(data, f)
# 修改json
with open('work_record.json', 'w+') as f:
data = json.load(f)
data['total_pulps'] += 28
data['total_carts'] += 1
data['average_pulp'] = int(data['total_pulps'] / data['total_carts'])
data['last_record'] = 28
data['day_count'] += 28
data['total_day_count'] += 28
data['test'] = 'test'
with open('work_record.json', 'a') as f:
json.dump(data, f)
import sqlite3
from config import PATH
class Databse:
def __init__(self):
self.conn = sqlite3.connect(PATH['database'])
self.cs = self.conn.cursor()
def createTable(self):
sql = '''CREATE TABLE jobs( id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
jobid INT NOT NULL,
time TEXT NOT NULL,
count INT NOT NULL,
path TEXT NOT NULL)'''
self.cs.execute(sql)
self.conn.commit()
def insertTable(self, time, count, path, jobid=None):
if jobid is not None:
sql = f'''INSERT INTO jobs (jobid, time, count, path)
VALUES ({jobid}, '{time}', {count}, '{path}')'''
print(sql)
self.cs.execute(sql)
self.conn.commit()
def deleteTable(self, id=None):
if id is not None:
sql = f'''DELETE FROM jobs WHERE id = {id}'''
self.cs.execute(sql)
self.conn.commit()
def modifyTable(self, column, value, id=None):
if id is not None:
sql = f'''UPDATE jobs set {column} = {value} WHERE id = {id}'''
self.cs.execute(sql)
self.conn.commit()
def searchTable(self, number, sql='select * from jobs'):
self.cs.execute(sql)
return self.cs.fetchmany(number)
def __del__(self):
self.cs.close()
self.conn.close()