kelangyang's picture
Upload 55 files
98aee8e verified
# -*- coding: utf-8 -*-
import json
from utils import engine
user_data_filepath = r"/home/yangkelang/program/novalConvertProject/data/userData/userData.json"
def save_dict_to_json_file(user, input_dict, file_path=user_data_filepath, mode='r+'):
with open(file_path, mode) as file:
data = json.load(file)
data[user].append(input_dict[1:])
file.seek(0)
json.dump(data, file)
# # 调用函数并传入用户名、字典和文件路径
# user = "2024001"
# input_dict = {"key1": "value1", "key2": "value2"}
# save_dict_to_json_file(user, input_dict)
def initialize_json_file(file_path):
data = {}
for i in range(2024001, 2024201):
data[str(i)] = []
with open(file_path, 'w') as file:
json.dump(data, file)
# # # 调用初始化函数并传入文件路径
# file_path = "../data/userData/userData.json"
# initialize_json_file(file_path)
def initialize_credentials_json(file_path):
data = {}
for i in range(2024001, 2024201):
data[str(i)] = "password123"
with open(file_path, 'w') as file:
json.dump(data, file)
# # 调用初始化函数并传入文件路径
# file_path = "../data/userData/userLogin.json"
# initialize_credentials_json(file_path)
json_path = r'/home/yangkelang/program/novalConvertProject/data/userData/userLogin.json'
def login(user_id, password, json_path=json_path):
with open(json_path, 'r') as file:
data = json.load(file)
if user_id in data and data[user_id] == password:
with open(r"C:\Users\Administrator\Desktop\PycharmProject\novalConvertProject\data\userData\usingUser.txt", 'w') as file:
file.write(user_id)#更新目前使用的id
return True
else:
return False
# 调用函数并输出结果
# file_path = "../data/userData/userLogin.json"
#
# result = login("2024001", "password123", file_path)
# print(result)