添加一个web API,以json格式显示当前用户的所有生词,以及添加某生词的总次数

鲁枭晨 2022-06-15 13:00:55 +08:00
parent 868fed795d
commit 1e846e5960
1 changed files with 6 additions and 10 deletions

View File

@ -29,16 +29,12 @@ def api_bp(username):
result = []
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
s = pickle_idea2.load_record(user_freq_record)
print(json.dumps(s))
wordlist = helper(s,result)
results = "{"
i=0
results = {}
for word in wordlist:
if i!=len(wordlist)-1:
results +='"' + word +'":' + str(len(s[word])) +","
i=i+1
else:
results += '"' + word + '":' + str(len(s[word]))
results+="}"
results[word]=len(s[word])
return results