|
@@ -0,0 +1,47 @@
|
|
|
+import json
|
|
|
+from time import sleep
|
|
|
+
|
|
|
+import requests
|
|
|
+
|
|
|
+filePath = """C:\\Users\\admin\\Downloads\\7-SAT-顺序.json"""
|
|
|
+
|
|
|
+url = 'https://app.yizhizs.cn/api/card'
|
|
|
+myHeaders = {
|
|
|
+ 'authorization': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlSWQiOiIzIiwidXNlck5hbWUiOiLlj7bovbvnnIkiLCJleHAiOjE3MjIxMjk4MjUsInVzZXJJZCI6IjEifQ.fIPuDsD3XfFlFsQxYobjjXz1s3puugbuicy-iNwfjTA',
|
|
|
+}
|
|
|
+# 读取文件内容,json格式
|
|
|
+with open(filePath, 'r', encoding='utf-8') as f:
|
|
|
+ data = f.read()
|
|
|
+ lines = json.loads(data)
|
|
|
+ num = 0
|
|
|
+ for line in lines:
|
|
|
+ jsonData = {
|
|
|
+ "cardBagId": "60412812777787392",
|
|
|
+ "cardType": "QUESTION_ANSWER",
|
|
|
+ "content": "{\"front\":\"<p>front-abcd</p>\",\"back\":{\"type\":\"QUESTION_ANSWER\",\"QUESTION_ANSWER\":{\"value\":\"<p>back-abcd</p>\"},\"MULTIPLE_CHOICE\":{\"values\":[{\"value\":\"\",\"checked\":false},{\"value\":\"\",\"checked\":false},{\"value\":\"\",\"checked\":false},{\"value\":\"\",\"checked\":false}]},\"TRUE_FALSE\":{\"value\":\"\"}}}"
|
|
|
+ }
|
|
|
+ num += 1
|
|
|
+ print(len(lines) - num)
|
|
|
+ try:
|
|
|
+ word = line['word']
|
|
|
+ translations = line['translations']
|
|
|
+
|
|
|
+ jsonData['content'] = jsonData['content'].replace('front-abcd', word)
|
|
|
+
|
|
|
+ backRes = f''
|
|
|
+ for translation in translations:
|
|
|
+ backRes += f'<p>{translation["type"]}. {translation["translation"]}</p>'
|
|
|
+ if 'phrases' in line:
|
|
|
+ phrases = line['phrases']
|
|
|
+ backRes = backRes + f'<br/><p>词组: </p>'
|
|
|
+ for phrase in phrases[:3]:
|
|
|
+ backRes += f"""<p class='custPhraseParent1'><span class='custPhrase1'>{phrase["phrase"]}</span><span class='custPhrase2'>{phrase["translation"]}</span></p>"""
|
|
|
+ jsonData['content'] = jsonData['content'].replace('back-abcd', backRes)
|
|
|
+ jsonData['content'] = json.loads(json.dumps(jsonData['content']))
|
|
|
+
|
|
|
+ response = requests.post(url, json=jsonData, headers=myHeaders, verify=False)
|
|
|
+ print(response.text)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+
|
|
|
+print('done')
|