d4bf750c9e
Initial commit
65 lines
835 B
Python
65 lines
835 B
Python
import json
|
|
import os
|
|
|
|
|
|
BASE = "/home/eg/profile-system"
|
|
FILE = os.path.join(
|
|
BASE,
|
|
"config/profile.json"
|
|
)
|
|
|
|
|
|
def load_profile():
|
|
|
|
with open(
|
|
FILE,
|
|
"r",
|
|
encoding="utf-8"
|
|
) as f:
|
|
|
|
return json.load(f)
|
|
|
|
|
|
|
|
def save_profile(data):
|
|
|
|
with open(
|
|
FILE,
|
|
"w",
|
|
encoding="utf-8"
|
|
) as f:
|
|
|
|
json.dump(
|
|
data,
|
|
f,
|
|
indent=4,
|
|
ensure_ascii=False
|
|
)
|
|
|
|
|
|
|
|
def set_value(name,value):
|
|
|
|
data = load_profile()
|
|
|
|
|
|
for item in data["dynamic"]:
|
|
|
|
if item["name"] == name:
|
|
|
|
item["value"] = value
|
|
save_profile(data)
|
|
return
|
|
|
|
|
|
data["dynamic"].append(
|
|
{
|
|
"type":1,
|
|
"name":name,
|
|
"value":value
|
|
}
|
|
)
|
|
|
|
|
|
save_profile(data)
|