main_word_applet.py 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. # -*- coding: UTF-8 -*-
  2. """专为鲍利提分小程序,制作的word文档;apifox接口在-单词教学宝-词汇突击学案文档生成接口"""
  3. import math
  4. import re
  5. import time
  6. from docx_base import Word, Table, ParagraphBase
  7. from random import shuffle
  8. from docx.shared import Inches
  9. from common.split_text import split_text_to_word_punctuation
  10. from config.read_config import address
  11. from make_docx_demo.data import *
  12. from make_docx_demo.docx_other_func import time_use, qrcode_maker, get_weekday
  13. from make_docx_demo.get_standard_data import get_standard_data
  14. from make_docx_demo.word2pdf import convert_word_to_pdf
  15. from tools.loglog import log_err_e
  16. num_dict = {1: "❶", 2: "❷", 3: "❸", 4: "❹", 5: "❺", 6: "❻", 7: "❼", 8: "❽", 9: "❾",
  17. 10: "❿", 11: "⓫", 12: "⓬", 13: "⓭", 14: "⓮", 15: "⓯", 16: "⓰", 17: "⓱", 18: "⓲", 19: "⓳", 20: "⓴"}
  18. @time_use
  19. def header_maker(docx: Word, json_data):
  20. exercise_id = str(json_data.get("ExerciseId", "")).rjust(11, "0")
  21. exercise_title = json_data.get("ExerciseTitle", "")
  22. exercise_level = json_data['StudentInfo']['StudentStudy']['ReadingLevel']
  23. student_name = json_data.get("StudentInfo").get("StudentName", '')
  24. class_name = json_data.get("StudentInfo").get("ClassName", '').replace("词汇突击", "")
  25. t_date = time.strftime("%Y-%m-%d", time.localtime())
  26. t_weekday = get_weekday()
  27. t_time = time.strftime("%H:%M:%S", time.localtime())
  28. for i in range(1, len(docx.doc.sections) - 1):
  29. tb_header = docx.add_header_table(rows=1, cols=5, section_index=i, tb_name="页眉表格")
  30. tb_header.set_cell_text(0, 0, "鲍利提分", bold=True, size=16, color=(220, 220, 220), border=False, chinese_font_name="黑体")
  31. tb_header.set_cell_text(0, 1, f"{class_name}\n{student_name}", size=8, border=False, color=(220, 220, 220))
  32. tb_header.set_cell_text(0, 2, f"词汇训练\n{exercise_level}级", size=8, border=False, color=(220, 220, 220))
  33. tb_header.set_cell_text(0, 3, f"{exercise_id}", bold=True, size=24, border=False, color=(220, 220, 220))
  34. tb_header.set_cell_text(0, 4, f"{t_date}\n{t_weekday}\n{t_time}", size=8, border=False, color=(220, 220, 220))
  35. tb_header.set_tb_colum_width(width=[100, 70, 70, 150, 80])
  36. target_section = docx.doc.sections[-1]
  37. target_section.header.is_linked_to_previous = False
  38. for paragraph in target_section.header.paragraphs:
  39. paragraph.clear()
  40. target_section.header_distance = 0
  41. target_section.footer_distance = 280000
  42. @time_use
  43. def sub_title_maker(docx: Word, main_title, sub_title_name1, sub_title_name2='鲍利提分,你的智能教练'):
  44. p = docx.add_blank_paragraph()
  45. line_width = 200
  46. main_rect_x = line_width + 10
  47. main_rect_width = 150
  48. right_line_x = main_rect_x + main_rect_width + 10
  49. p.add_rectangle(main_title, x=main_rect_x, y=4, fill_color="000000", width=main_rect_width, height=48, font_color="ffffff",
  50. font_size=18)
  51. p.add_rectangle("", x=0, y=50, boder_color="808080", width=line_width, height=2)
  52. p.add_rectangle("", x=right_line_x, y=50, boder_color="808080", width=line_width, height=2)
  53. p.add_rectangle(f"【{sub_title_name1}】", x=0, y=20, width=line_width, height=40, font_size=8, chinese_font="宋体")
  54. p.add_rectangle(sub_title_name2, x=right_line_x, y=20, width=line_width, height=40, font_color="808080", font_size=8,
  55. chinese_font="宋体")
  56. docx.add_blank_paragraph()
  57. docx.add_blank_paragraph()
  58. docx.add_blank_paragraph()
  59. @time_use
  60. def section_1(docx: Word, json_data, *args, **kwargs):
  61. exercise_id_int = json_data.get("ExerciseId", "")
  62. student_name = json_data.get("StudentInfo").get("StudentName", '')
  63. student_stage = json_data.get("StudentInfo").get("StudentStage")
  64. grade_name = {1: "小学", 2: "初中", 3: "高中"}.get(student_stage)
  65. t_date_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  66. totalVocabulary, readingAccuracy, readingLevel, readingSpeed = get_standard_data(student_stage)
  67. FirstVocabulary = json_data['StudentInfo']['StudentStudy']['FirstVocabulary']
  68. Vocabulary = json_data['StudentInfo']['StudentStudy']['Vocabulary']
  69. ReadingVolume = json_data['StudentInfo']['StudentStudy']['ReadingVolume']
  70. r6 = json_data['StudentInfo']['StudentStudy']['ReadingLevel']
  71. r7 = len([strange_words for exercise in json_data['WordAndArticleContents'] for strange_words in exercise['StrangeWords']])
  72. r8 = r6
  73. multi_article_difficulty = [article_obj['Score'] for article_obj in json_data['WordAndArticleContents'][0]['Articles']]
  74. difficulty_value = sum(multi_article_difficulty) // len(multi_article_difficulty) if multi_article_difficulty else 0
  75. InspirationalMessage = json_data.get('InspirationalMessage')
  76. "开始版面-------------------------------------------------"
  77. docx.add_paragraph(text="鲍利提分个性化学案", size=20, align="center", bold=True)
  78. docx.add_paragraph(text="AI解码英语基因,智能重组高分密码", size=14, align="center")
  79. docx.add_blank_paragraph()
  80. docx.add_paragraph(text="学生基本情况", size=16, align="left", bold=True, dq=10, dh=5)
  81. t1 = Table(docx, 0, 3, border=True, tb_name="学生基本情况")
  82. t1.add_table_row_data_xml_fastly(["姓名", "年级", "初始词汇量"])
  83. t1.add_table_row_data_xml_fastly([student_name, grade_name, FirstVocabulary])
  84. t1.add_table_row_data_xml_fastly(["当前词汇量", "学段总词汇量", "累计阅读量"])
  85. t1.add_table_row_data_xml_fastly([Vocabulary, totalVocabulary, ReadingVolume])
  86. t1.set_all_border_fastly(xml=True)
  87. t1.set_ALIGN_VERTICAL()
  88. t1.set_row_height(row_height=20)
  89. docx.add_blank_paragraph()
  90. docx.add_paragraph(text="本次学案难度情况", size=16, align="left", bold=True, dq=10, dh=5)
  91. t3 = Table(docx, 0, 4, border=False, tb_name="本次学案难度情况")
  92. t3.add_table_row_data_xml_fastly(["指标", "生词数量", "阅读难度等级", "文章词汇难度值"])
  93. t3.add_table_row_data_xml_fastly(["本次内容", f"{r7}个", r8, difficulty_value])
  94. t3.set_all_border_fastly(xml=True)
  95. t3.set_ALIGN_VERTICAL()
  96. t3.set_row_height(row_height=20)
  97. docx.add_blank_paragraph()
  98. if InspirationalMessage:
  99. docx.add_paragraph(text="寄语", size=16, align="left", bold=True, dq=10, dh=5)
  100. t4 = Table(docx, 0, 1, border=False, tb_name="封面的寄语")
  101. t4.add_table_row_data_xml_fastly([InspirationalMessage], )
  102. t4.set_all_border_fastly(xml=True)
  103. t4.set_ALIGN_VERTICAL()
  104. t4.set_row_height(row_height=50)
  105. t4.set_tb_colum_width(0, 500)
  106. docx.add_blank_paragraph()
  107. docx.add_paragraph(text="练习提醒Tips", size=16, align="left", bold=True, dq=10, dh=5)
  108. t5 = Table(docx, 0, 1, border=False, tb_name="本次学案难度情况")
  109. text = "请认真阅读,不可急于求成,要确保能够理解每一句话,不要满足于略知概要,不要跳读略读,不要猜答案,加油!"
  110. t5.add_table_row_data_xml_fastly([text], )
  111. t5.set_all_border_fastly(xml=True)
  112. t5.set_ALIGN_VERTICAL()
  113. t5.set_row_height(row_height=50)
  114. t5.set_tb_colum_width(0, 500)
  115. docx.add_paragraph(text="多媒体辅助", size=16, align="left", bold=True, dq=10, dh=5)
  116. docx.add_paragraph(text="需要示范的的学员,扫以下二维码获取音频、视频示范:", size=12, align="left", dq=5, dh=5)
  117. p = docx.add_blank_paragraph()
  118. img_io = qrcode_maker(full_url=f"{address}/link?type=exercise&id={exercise_id_int}&from=bltf")
  119. p.add_pic(img_io, width=2)
  120. img_io.close()
  121. docx.add_paragraph(text=f"生成时间: {t_date_time}", size=12, align="left", dq=10)
  122. docx.add_page_section()
  123. @time_use
  124. def section_4(docx: Word, json_data, *args, **kwargs):
  125. student_name = json_data.get("StudentInfo").get("StudentName", '')
  126. title_info = "\n".join(json_data.get("Title"))
  127. if title_info:
  128. docx.add_paragraph(f"{student_name} 同学:", align="center", bold=True, dq=5, dh=5)
  129. p1 = docx.add_blank_paragraph()
  130. p1.add_run_to_p(title_info, size=10)
  131. sub_title_maker(docx, "词汇精准学", "智能定制你的专属英语DNA图谱")
  132. tb = Table(docx, 1, 1, border=True, tb_name="词汇精准学")
  133. tb.set_tb_colum_width(0, 460)
  134. tb.set_cell_text(0, 0, "按顺序朗读生词表两遍。\n(1)用红笔在不会的单词序号上打星号,增加记忆。\n(2)朗读例句,不认识的部分参照译文理解。",
  135. align="left", size=10, dq=10, dh=10)
  136. docx.add_blank_paragraph()
  137. @time_use
  138. def section_4_1(docx: Word, json_data, *args, **kwargs):
  139. def insert_content(row, col, data, qrcode_result: dict):
  140. cell_outside = tb_outside.get_cell(row, col, delete_default_para=True)
  141. tb_inside = Table(cell_outside, rows=5, cols=3, tb_name="内部内容")
  142. tb_inside.merge_cell(0, 0, 0, 2)
  143. tb_inside.merge_cell(1, 0, 1, 2)
  144. tb_inside.merge_cell(2, 0, 2, 2)
  145. tb_inside.merge_cell(3, 0, 3, 2)
  146. tb_inside.merge_cell(4, 0, 4, 2)
  147. num_calucate = 2 * row + 1 if col == 0 else 2 * row + 2
  148. p = ParagraphBase(tb_inside.get_cell_paragraph(0, 0, align="left"))
  149. p.add_run_to_p(num_dict[num_calucate], bold=True, size=22, font_name="MS Gothic")
  150. p.add_run_to_p(' ' + data[0], bold=True, size=20)
  151. tb_inside.set_cell_text(row=1, column=0, cell_text=data[1] + " " + data[2], border=False, size=10, align="left",
  152. bk_color=(240, 240, 240))
  153. cell_p = tb_inside.get_cell_paragraph(2, 0, align="left")
  154. cell_p_1 = ParagraphBase(cell_p)
  155. cell_p_1.add_run_to_p(data[3], size=10, bold=True)
  156. cell_p_1.add_run_to_p(" " + data[4], size=8)
  157. cell_p = tb_inside.get_cell_paragraph(3, 0, align="left")
  158. cell_p_1 = ParagraphBase(cell_p)
  159. cell_p_1.add_run_to_p(data[5], size=10, bold=True)
  160. cell_p_1.add_run_to_p(" " + data[6], size=8)
  161. cell_p = tb_inside.get_cell_paragraph(4, 0, align="left")
  162. cell_p_1 = ParagraphBase(cell_p)
  163. cell_p_1.add_run_to_p(data[7], size=10, bold=True)
  164. cell_p_1.add_run_to_p(" " + data[8], size=8)
  165. properties_chinese_map = {"adj": "形容词", "n": "名词", "interj": "感叹词", "conj": "连词", "num": "数字", "art": "冠词",
  166. "pron": "代词", "adv": "副词", "prep": "介词", "v": "动词"}
  167. strange_words_data = []
  168. strange_words = json_data.get('StrangeWords')
  169. qrcode_thread = []
  170. qrcode_result = {}
  171. for item in strange_words:
  172. spell = item['Spell']
  173. word_id = item['WordId']
  174. en = "" if not item.get("SymbolsEn", "") else item.get("SymbolsEn")
  175. am = "" if not item.get("SymbolsAm", "") else item.get("SymbolsAm")
  176. symbols_en = "英" + f'[{en}]'
  177. symbols_am = "美" + f'[{am}]'
  178. word_properties = " ".join([properties_chinese_map.get(i, "") for i in item['WordProperties']])
  179. word_meanings = item.get('Meaning', "")
  180. word_changes_list = []
  181. for idx, s in enumerate(item["WordChanges"], start=1):
  182. s_type, s_spell = s['Type'], s['Spell']
  183. if "原型" in s_type or "大小写" in s_type:
  184. continue
  185. tail = '\n' if idx != len(item["WordChanges"]) else ''
  186. word_changes_list.append(f"{s_spell} {s_type}{tail}")
  187. word_changes = "".join(word_changes_list)
  188. if item['Sentences']:
  189. sentences = item['Sentences'][0]['English'] + '\n' + item['Sentences'][0]['Chinese']
  190. else:
  191. sentences = ""
  192. single_word_tuple = (spell, symbols_en, symbols_am, word_properties, word_meanings,
  193. "词汇变形", word_changes, "例句", sentences)
  194. strange_words_data.append(single_word_tuple)
  195. rows = math.ceil(len(strange_words_data) / 2)
  196. tb_outside = Table(docx, rows=rows, cols=2, tb_name="外层框架")
  197. tb_outside.set_tb_colum_width(width=[230, 230])
  198. for t in qrcode_thread:
  199. t.join()
  200. for row in range(rows):
  201. for col in range(2):
  202. try:
  203. data_item = strange_words_data.pop(0)
  204. insert_content(row, col, data_item, qrcode_result)
  205. except IndexError:
  206. break
  207. docx.add_page_section()
  208. @time_use
  209. def section_5(docx: Word, json_data, *args, **kwargs):
  210. copy_word_list = [i['Meaning'] for i in json_data.get('StrangeWords')]
  211. random_copy_word_list = copy_word_list * 3
  212. shuffle(random_copy_word_list)
  213. first_copy_word_list = copy_word_list.copy()
  214. copy_word_list_add_num = [f"{i} ({idx})" for idx, i in enumerate(first_copy_word_list, start=1)]
  215. shuffle(copy_word_list_add_num)
  216. total_copy_word_list = copy_word_list_add_num + random_copy_word_list
  217. sub_title_maker(docx, "单词高效记", "会读会写才算真学会")
  218. tb = Table(docx, 1, 1, tb_name="高效速记", border=True)
  219. tb.set_tb_colum_width(0, 460)
  220. text = ["请在横线上写下对应单词,每格写一遍,尽量默写,默写不出的,可查阅生词表;\n",
  221. "书写时保持工整;每写完一个单词小声念一遍词义与单词。\n"]
  222. cell_p = tb.get_cell_paragraph(0, 0, align="left")
  223. p = ParagraphBase(cell_p)
  224. p.add_run_to_p(" 高效速记\n", size=16, bold=True, )
  225. for t in text:
  226. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  227. p.add_run_to_p(t, size=10)
  228. docx.add_blank_paragraph()
  229. total_count = len(total_copy_word_list)
  230. half_count = int(total_count / 2)
  231. tb2 = Table(docx, half_count + 1, 4, tb_name="高效速记下面的单词")
  232. for row in range(total_count):
  233. data = total_copy_word_list[row]
  234. if row < half_count:
  235. tb2.set_cell_text(row, 0, data, size=9, align="right", border=False, dq=2.5, dh=2)
  236. tb2.set_cell_text(row, 1, str(row + 1) + "." + "_" * 20, size=9, align="left", border=False, dq=2.5, dh=2)
  237. else:
  238. tb2.set_cell_text(row - half_count, 2, data, size=9, align="right", border=False, dq=2.5, dh=2)
  239. tb2.set_cell_text(row - half_count, 3, str(row + 1) + "." + "_" * 20, size=9, align="left", border=False, dq=2.5, dh=2)
  240. tb2.set_tb_colum_width(width=[120, 110] * 2)
  241. docx.add_page_section()
  242. @time_use
  243. def section_6(docx: Word, json_data, *args, **kwargs):
  244. example_sentence = [f"{index}. {i['Sentences'][0]['English']} ({i['Spell']})" for index, i in
  245. enumerate(json_data['StrangeWords'], start=1) if i['Sentences']]
  246. sub_title_maker(docx, "例句填填看", "记词义,练拼写,学的快")
  247. tb = Table(docx, 1, 1, tb_name="例句填填看", border=True)
  248. tb.set_tb_colum_width(0, 460)
  249. text = ["请在横线上写下单词在例句中的词义,若想不起来,可随时到例句答案表中查看。\n",
  250. "参阅过答案的例句,请在句前的“□”中标记问号,以便复习回顾。\n",
  251. "单词有多个意思的,应只填写适合语境的意思。\n",
  252. "例句中有不熟悉的单词,请用斜线划掉,以便拍照报告给我们。"]
  253. cell_p = tb.get_cell_paragraph(0, 0, align="left", dq=10, dh=10)
  254. p = ParagraphBase(cell_p)
  255. for t in text:
  256. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  257. p.add_run_to_p(t, size=10)
  258. for i in example_sentence:
  259. p = docx.add_blank_paragraph(dq=4, dh=4)
  260. p.add_run_to_p("□ ", size=12, font_name="宋体")
  261. p.add_run_to_p(i + "___________")
  262. docx.add_page_section()
  263. @time_use
  264. def section_7(docx: Word, json_data, *args, **kwargs):
  265. def wanxing(index, article_single):
  266. article_id = article_single['Id']
  267. article_length = article_single['AllWordAmount']
  268. strange_words_ids = [i['MeanId'] for i in json_data['StrangeWords']]
  269. explanatory_words_ids = [i['MeaningId'] for i in article_single['ExplanatoryWords']]
  270. select_text = []
  271. for ques_index, candidates in enumerate(article_single['Questions'], start=1):
  272. single_select_text = ''
  273. for s in candidates['Candidates']:
  274. single_select_text += s['Label'] + '. '
  275. participle = s['Participle']
  276. if participle:
  277. single_select_text += participle + ' \n'
  278. else:
  279. text = s['Text']
  280. single_select_text += text + ' \n'
  281. select_text.append(f"{ques_index}. {single_select_text}")
  282. all_select_text = "\n".join(select_text)
  283. article_main: str = article_single['English'] + "\n\n郑重提示:认真看完全文再看问题。\n\n" + all_select_text
  284. article_main_list = article_main.split(" ")
  285. explanatory_words = "\n\n".join(
  286. [f"{index}. {i['Spell']} [{i['SymbolsEn']}] [{i['SymbolsAm']}] {i['Meaning']}" for index, i in
  287. enumerate(article_single['ExplanatoryWords'], start=1)])
  288. sub_title_maker(docx, "真题强化练", "智能匹配难度,轻松提升阅读")
  289. tb = Table(docx, 1, 1, tb_name="真题强化练", border=True)
  290. tb.set_tb_colum_width(0, 460)
  291. text = ["练习中不认识的单词,尽量猜测词义,并用斜线划掉,以便拍照报告给我们。\n\n",
  292. "答题完毕后,可查字典,并注释在右侧批注区,不要在原文上注释。复习时不必通读全文,结合上下文能回忆起标记词的词义即可,想不起的再对照批注区。\n",
  293. "完形填空是优秀的测验题型,却不适合用于训练阅读能力和提升词汇量,所以建议在阅读能力(理解度、速度、难度)达标后再做完形填空题型练习。\n",
  294. "阅读能力达标的同学,按三遍法做完形填空,基本可以达到满分。三遍法要求如下:\n",
  295. "第一遍(理解):结合选项通读全文,以求理解文章主旨,但不动笔,以免形成成见。\n",
  296. "第二遍(填空):通读全文,从候选词中选出适宜项目,将完整的单词填入空格,使文章连贯。\n",
  297. "第三遍(核验):通读填空后的全文,确认上下文无矛盾之处。\n",
  298. "三遍通读均应记录起讫时间,并将速度纳入能力考核项目。能力合格者,考试中也应有充裕时间完成以上 3 遍通读。\n",
  299. "阅读计时从此处开始,请按顺序完成阅读,并注意记录时间。"]
  300. text2 = [f"全题长度(含问题及选项):{article_length}; 编号:{article_id};\n",
  301. "第一遍(理解)开始时间:_________________ 第二遍(填空)开始时间:_________________\n",
  302. "第三遍(核验)开始时间:_________________"]
  303. cell_p = tb.get_cell_paragraph(0, 0, align="left", dq=10, dh=10)
  304. p = ParagraphBase(cell_p)
  305. for t in text:
  306. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  307. p.add_run_to_p(t, size=10)
  308. for t2 in text2:
  309. p.add_run_to_p(t2, size=10)
  310. docx.add_blank_paragraph()
  311. tb1 = Table(docx, 1, 3)
  312. tb1.set_tb_colum_width(width=[90, 370, 5])
  313. tb1_p = ParagraphBase(tb1.get_cell_paragraph(0, 0, align="left"))
  314. tb1_p.add_pic("make_docx_demo/static/lianxi1.jpg", width=2.5)
  315. tb1.set_cell_text(0, 1, f"篇幅(含问题选项):{article_length} 词 阅读开始时间:_____点_____分_____秒",
  316. size=9.5, border=False, align="left")
  317. tb2 = Table(docx, rows=1, cols=2, border=True, tb_name="完形填空")
  318. tb2.set_tb_colum_width(width=[320, 140])
  319. tb2_p = ParagraphBase(tb2.get_cell_paragraph(0, 0, align="left"))
  320. for w in article_main_list:
  321. word = re.search(r"\[(\d+)]", w)
  322. if word:
  323. w = w[:w.find('[')]
  324. meaning_id = int(word.group(1))
  325. if meaning_id in strange_words_ids:
  326. tb2_p.add_run_to_p(w + ' ', size=10.5, bold=True)
  327. elif meaning_id in explanatory_words_ids:
  328. tb2_p.add_run_to_p(w + ' ', size=10.5, italic=True)
  329. else:
  330. tb2_p.add_run_to_p(w + ' ', size=10.5)
  331. else:
  332. tb2_p.add_run_to_p(w + ' ', size=10.5)
  333. tb2.set_cell_text(0, 1, explanatory_words, size=10.5, font_color=(80, 80, 80), align="left")
  334. docx.add_blank_paragraph()
  335. tail_zhushi = """第一遍(理解)结束时间:__________用时:____秒
  336. 第二遍(填空)结束时间:__________用时:____秒
  337. 第三遍(核验)结束时间:__________用时:____秒
  338. 总计用时:____分____秒
  339. """
  340. docx.add_paragraph(tail_zhushi, size=10.5)
  341. docx.add_blank_paragraph()
  342. def reading(index, article_single):
  343. def single_yuedu(index, a):
  344. article_id = a['Id']
  345. article_length = a['AllWordAmount']
  346. strange_words_ids = set()
  347. explanatory_words_ids = set()
  348. bold_word = set()
  349. italics_word = set()
  350. italics_index_dict = {}
  351. for i in json_data['StrangeWords']:
  352. strange_words_ids.add(i['MeanId'])
  353. bold_word.add(i['Spell'])
  354. bold_word.update([change_word['Spell'] for change_word in i['WordChanges']])
  355. for italics_index, ii in enumerate(a['ExplanatoryWords'], start=1):
  356. explanatory_words_ids.add(ii['MeaningId'])
  357. italics_word.add(ii['Spell'])
  358. if 'WordChanges' in ii:
  359. italics_word.update([change_word['Spell'] for change_word in ii['WordChanges']])
  360. italics_index_dict.update({change_word['Spell']: f"[{italics_index}]" for change_word in ii['WordChanges']})
  361. italics_index_dict[ii['MeaningId']] = f"[{italics_index}]"
  362. italics_index_dict[ii['Spell']] = f"[{italics_index}]"
  363. select_text = []
  364. for ques_index, candidates in enumerate(a['Questions'], start=1):
  365. single_select_text = ''
  366. subject = candidates['Subject'] + '\n'
  367. for s in candidates['Candidates']:
  368. single_select_text += s['Label'] + '. '
  369. participle = s['Participle']
  370. if participle:
  371. single_select_text += participle + ' \n'
  372. else:
  373. text = s['Text']
  374. single_select_text += text + ' \n'
  375. select_text.append(str(ques_index) + ". " + subject + single_select_text)
  376. all_select_text = "\n".join(select_text)
  377. article_main: str = a['English'] + "\n\n郑重提示:认真看完全文再看问题。\n" + all_select_text
  378. article_main_list = split_text_to_word_punctuation(article_main)
  379. explanatory_words = "\n\n".join(
  380. [f"{index}. {i['Spell']}\n [{i['SymbolsEn']}] [{i['SymbolsAm']}]\n {i['Meaning']}" for index, i in
  381. enumerate(a['ExplanatoryWords'], start=1)])
  382. tb1 = Table(docx, 1, 3, tb_name="图片小标题")
  383. tb1.set_tb_colum_width(width=[90, 370, 5])
  384. tb1_p = ParagraphBase(tb1.get_cell_paragraph(0, 0, align="left"))
  385. tb1_p.add_pic(f"make_docx_demo/static/lianxi{index}.jpg", width=2.5)
  386. tb1.set_cell_text(0, 1, f"篇幅(含问题选项):{article_length} 词 阅读开始时间:_____点_____分_____秒",
  387. size=9.5, border=False, align="left")
  388. tb2 = Table(docx, rows=1, cols=2, border=True, tb_name="阅读")
  389. tb2.set_tb_colum_width(width=[320, 140])
  390. tb2_p = ParagraphBase(tb2.get_cell_paragraph(0, 0, align="left"))
  391. for w in article_main_list:
  392. word = re.search(r"\[(\d+)]", w)
  393. if word:
  394. w = w[:w.find('[')]
  395. meaning_id = int(word.group(1))
  396. if meaning_id in strange_words_ids:
  397. tb2_p.add_run_to_p(w + ' ', size=10.5, bold=True)
  398. elif meaning_id in explanatory_words_ids:
  399. italics_index_str = italics_index_dict[meaning_id]
  400. tb2_p.add_run_to_p(w + f'{italics_index_str} ', size=10.5, italic=True)
  401. else:
  402. tb2_p.add_run_to_p(w + ' ', size=10.5)
  403. else:
  404. if w in bold_word:
  405. tb2_p.add_run_to_p(w + ' ', size=10.5, bold=True)
  406. elif w in italics_word:
  407. italics_index_str = italics_index_dict[w]
  408. tb2_p.add_run_to_p(w + f'{italics_index_str} ', size=10.5, italic=True)
  409. else:
  410. tb2_p.add_run_to_p(w + ' ', size=10.5)
  411. tb2.set_cell_text(0, 1, explanatory_words, size=10.5, font_color=(80, 80, 80), align="left", centre=False, line_spacing=300)
  412. docx.add_blank_paragraph()
  413. tail_zhushi = """完成时间:_____点_____分_____秒,本篇用时:_____秒。"""
  414. docx.add_paragraph(tail_zhushi, size=10.5)
  415. docx.add_blank_paragraph()
  416. def top_header():
  417. sub_title_maker(docx, "阅读提升练", "智能匹配难度,轻松提升阅读", "鲍利提分, 高效学习专家")
  418. tb = Table(docx, 1, 1, tb_name="真题强化练", border=True)
  419. tb.set_tb_colum_width(0, 460)
  420. text = ["阅读中不认识的单词,尽量猜测词义,并用斜线划掉,以便拍照报告给我们。\n",
  421. "读完全文后,可查字典,并抄在右侧批注区,不要在原文上注释。复习时不必通读全文,结合上下文能回忆起标记词的词义即可,想不起的再对照批注区。\n",
  422. "阅读训练的目的是提高对英语词、句、篇的敏感度,答题只是检验学习成果的手段,所以切勿为了快速做题而跳读、略读。阅读速度是很重要的训练指标,请在确实理解词句的基础上尽量提高阅读速度。只要平时扎实阅读,考试中不会没有时间认真读题。\n",
  423. "阅读计时从此处开始,请按顺序完成阅读,并注意记录时间。\n\n",
  424. "生词划线示例:competitions she once attended. Incuding her years of experience"
  425. ]
  426. cell_p = tb.get_cell_paragraph(0, 0, align="left", dq=10, dh=10)
  427. pp = ParagraphBase(cell_p)
  428. for index_t, t in enumerate(text):
  429. if index_t == len(text) - 1:
  430. pp.add_run_to_p(t, size=12)
  431. pp.add_rectangle('', x=115, y=170, width=55, height=25, boder_color='000000', shape_type='line')
  432. pp.add_rectangle('', x=298, y=170, width=55, height=25, boder_color='000000', shape_type='line')
  433. else:
  434. pp.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  435. pp.add_run_to_p(t, size=10)
  436. docx.add_blank_paragraph()
  437. "---------------------开始单篇运行---------------------"
  438. if index == 1:
  439. top_header()
  440. single_yuedu(index, article_single)
  441. def seven_to_five(index, article_single):
  442. article_id = article_single['Id']
  443. article_length = article_single['AllWordAmount']
  444. strange_words_ids = [i['MeanId'] for i in json_data['StrangeWords']]
  445. explanatory_words_ids = [i['MeaningId'] for i in article_single['ExplanatoryWords']]
  446. select_text = []
  447. for ques_index, s_candidates in enumerate(article_single['Candidates'], start=1):
  448. single_select_text = ''
  449. single_select_text += s_candidates['Label'] + '. '
  450. participle = s_candidates['Participle']
  451. if participle:
  452. single_select_text += participle
  453. else:
  454. text = s_candidates['Text']
  455. single_select_text += text
  456. select_text.append(f"{single_select_text}")
  457. all_select_text = "\n".join(select_text)
  458. article_main: str = article_single['English'] + "\n\n郑重提示:认真看完全文再看问题。\n\n" + all_select_text
  459. article_main_list = article_main.split(" ")
  460. explanatory_words = "\n\n".join(
  461. [f"{index}. {i['Spell']} [{i['SymbolsEn']}] [{i['SymbolsAm']}] {i['Meaning']}" for index, i in
  462. enumerate(article_single['ExplanatoryWords'], start=1)])
  463. sub_title_maker(docx, "阅读提升练", "智能匹配难度,轻松提升阅读", "鲍利提分, 高效学习专家")
  464. tb = Table(docx, 1, 1, tb_name="真题强化练", border=True)
  465. tb.set_tb_colum_width(0, 460)
  466. text = ["阅读中不认识的单词,尽量猜测词义,并用斜线划掉,以便拍照报告给我们。\n",
  467. "读完全文后,可查字典,并抄在右侧批注区,不要在原文上注释。复习时不必通读全文,结合上下文能回忆起标记词的词义即可,想不起的再对照批注区。\n",
  468. "7 选 5 题型是测试学生对文章理解程度的好题型,但因打破里文章的连贯性,故不是训练阅读能力的好素材。建议学生在阅读基本能力(理解度、速度、难度)达标后再开展 7 选 5 题型训练。若不能胜任本练习,请回到词汇与阅读训练,先打好基础。\n",
  469. "阅读计时从此处开始,请按顺序完成阅读,并注意记录时间。"]
  470. cell_p = tb.get_cell_paragraph(0, 0, align="left", dq=10, dh=10)
  471. p = ParagraphBase(cell_p)
  472. for t in text:
  473. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  474. p.add_run_to_p(t, size=10)
  475. docx.add_blank_paragraph()
  476. tb1 = Table(docx, 1, 3, tb_name="图片小标题")
  477. tb1.set_tb_colum_width(width=[90, 370, 5])
  478. tb1_p = ParagraphBase(tb1.get_cell_paragraph(0, 0, align="left"))
  479. tb1_p.add_pic("make_docx_demo/static/lianxi1.jpg", width=2.5)
  480. tb1.set_cell_text(0, 1, f"篇幅(含问题选项):{article_length} 词 阅读开始时间:_____点_____分_____秒",
  481. size=9.5, border=False, align="left")
  482. tb2 = Table(docx, rows=1, cols=2, border=True, tb_name="七选五")
  483. tb2.set_tb_colum_width(width=[320, 140])
  484. tb2_p = ParagraphBase(tb2.get_cell_paragraph(0, 0, align="left"))
  485. for w in article_main_list:
  486. word = re.search(r"\[(\d+)]", w)
  487. if word:
  488. w = w[:w.find('[')]
  489. meaning_id = int(word.group(1))
  490. if meaning_id in strange_words_ids:
  491. tb2_p.add_run_to_p(w + ' ', size=10.5, bold=True)
  492. elif meaning_id in explanatory_words_ids:
  493. tb2_p.add_run_to_p(w + ' ', size=10.5, italic=True)
  494. else:
  495. tb2_p.add_run_to_p(w + ' ', size=10.5)
  496. else:
  497. tb2_p.add_run_to_p(w + ' ', size=10.5)
  498. tb2.set_cell_text(0, 1, explanatory_words, size=10.5, font_color=(80, 80, 80), align="left")
  499. docx.add_blank_paragraph()
  500. "判断题型;根据题型选择----------------------------"
  501. all_article_length = 0
  502. for index, article_single in enumerate(json_data['Articles'], start=1):
  503. article_type = article_single['Category']
  504. article_type_select = {1: reading, 2: wanxing, 3: seven_to_five}
  505. assert article_type in article_type_select
  506. article_type_select[article_type](index, article_single)
  507. article_length = article_single['AllWordAmount']
  508. all_article_length += article_length
  509. tail_zhushi = f"""阅读计时在此结束。
  510. 今日总计阅读量 {all_article_length} 词,用时________秒,整份学案共有_______个题目答对。"""
  511. docx.add_paragraph(tail_zhushi, size=10.5)
  512. docx.add_blank_paragraph()
  513. docx.add_page_section()
  514. @time_use
  515. def section_9(docx: Word, json_data, *args, **kwargs):
  516. def wanxing(index, article_count, article_single):
  517. chinese_article = article_single['Chinese']
  518. all_analysis = ''
  519. docx.add_paragraph("答案和解析", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  520. for ques_index, question_item in enumerate(article_single['Questions'], start=1):
  521. analysis = question_item['Analysis'].strip()
  522. abcd_label = ''
  523. candidates = question_item['Candidates']
  524. for abcd_selected in candidates:
  525. if abcd_selected['IsRight']:
  526. abcd_label += abcd_selected['Label'].strip()
  527. all_analysis += f"{ques_index}.\n{abcd_label} {analysis}\n"
  528. docx.add_paragraph(all_analysis, size=9)
  529. docx.add_paragraph("全文参考译文", chinese_font_name="微软雅黑", dq=15, dh=5, bold=True)
  530. docx.add_paragraph(chinese_article, size=9, dq=5, dh=5, line_spacing=300)
  531. def reading(index, article_count, article_single):
  532. """
  533. index : 外面传入,从1开始。如果只有
  534. """
  535. all_analysis = ''
  536. all_difficult_sentences = []
  537. chinese_article = article_single['Chinese']
  538. questions = article_single['Questions']
  539. for ques_index, question_item in enumerate(questions, start=1):
  540. analysis = question_item['Analysis'].strip("\n")
  541. abcd_label = ''
  542. candidates = question_item['Candidates']
  543. for abcd_selected in candidates:
  544. if abcd_selected['IsRight']:
  545. abcd_label += abcd_selected['Label'].strip("\n")
  546. new_line = "" if ques_index == len(questions) else "\n"
  547. all_analysis += f"{ques_index}.{abcd_label} {analysis}{new_line}"
  548. if index != article_count:
  549. all_analysis += '\n'
  550. docx.add_paragraph(f"Passage {index}", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True, size=16)
  551. docx.add_paragraph("全文参考译文", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  552. docx.add_paragraph(chinese_article, size=9)
  553. docx.add_paragraph("答案和解析", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  554. docx.add_paragraph(all_analysis, size=9)
  555. def seven_to_five(index, article_count, article_single):
  556. chinese_article = article_single['Chinese']
  557. all_analysis = ''
  558. docx.add_paragraph("答案和解析", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  559. for q_index, question_item in enumerate(article_single['Questions'], start=1):
  560. analysis = question_item['Analysis']
  561. abcd_label = ''
  562. candidates = question_item['Candidates']
  563. for abcd_selected in candidates:
  564. if abcd_selected['IsRight']:
  565. abcd_label += abcd_selected['Label']
  566. all_analysis += f"{q_index}.{abcd_label} {analysis}\n"
  567. docx.add_paragraph(all_analysis, size=9)
  568. docx.add_paragraph("全文参考译文", chinese_font_name="微软雅黑", dq=15, dh=5, bold=True)
  569. docx.add_paragraph("Passage 1", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  570. docx.add_paragraph(chinese_article, size=9, dq=5, dh=5, line_spacing=300)
  571. "判断题型;根据题型选择----------------------------"
  572. sub_title_maker(docx, "解题自主纠", "自主学习,逐步养成良好学习习惯", "鲍利提分,你的智能教练")
  573. articles = json_data['Articles']
  574. article_count = len(articles)
  575. for index, article_single in enumerate(articles, start=1):
  576. article_type = article_single['Category']
  577. article_type_select = {1: reading, 2: wanxing, 3: seven_to_five}
  578. assert article_type in article_type_select
  579. article_type_select[article_type](index, article_count, article_single)
  580. docx.add_docx_component("make_docx_demo/word_component/blank.docx")
  581. docx.add_page_section()
  582. @time_use
  583. def section_10(docx: Word, json_data, scanpage_format, *args, **kwargs):
  584. docx.add_paragraph("☆ 请写出词义,再对照筛査表批改。词义顺序可互换;答案意思相符即可,不要求一字不差。批改结果眷抄到筛査表。", size=9, dq=2,
  585. dh=2)
  586. tb = Table(docx, 50, 4, tb_name="写出词义")
  587. tb.set_tb_colum_width(width=[110, 120, 110, 120])
  588. for row in range(50):
  589. tb.set_cell_text(row, 0, str(row + 1) + " " + "rich", size=8.5, dq=1, dh=1, border=False)
  590. tb.set_cell_text(row, 1, "□________________", size=10, dq=0, dh=0, border=False)
  591. tb.set_cell_text(row, 2, str(row + 51) + " " + "rich", size=8.5, dq=1, dh=1, border=False)
  592. tb.set_cell_text(row, 3, "□________________", size=10, dq=0, dh=0, border=False)
  593. tb.set_row_height(13)
  594. docx.add_page_break()
  595. docx.add_paragraph("☆ 请在需要加强学习的词义前方框中划线,两头各超出 1 毫米为宜(示例:□☑52.example);请保持本表整洁并交回。", size=9, dq=2,
  596. dh=2)
  597. tb2 = Table(docx, 25, 8, tb_name="划线表")
  598. tb2.set_tb_colum_width(width=[57.5] * 8)
  599. docx.add_blank_paragraph(dq=5, dh=5)
  600. for row in range(25):
  601. tb2.set_cell_text(row, 0, "[01] Tuesday", size=8.5, border=False, dq=1.2, dh=1.2)
  602. tb2.set_cell_text(row, 1, "星期二", size=8.5, border="right", dq=1.2, dh=1.2)
  603. tb2.set_cell_text(row, 2, "[01] Tuesday", size=8.5, border=False, dq=1.2, dh=1.2)
  604. tb2.set_cell_text(row, 3, "星期二", size=8.5, border="right", dq=1.2, dh=1.2)
  605. tb2.set_cell_text(row, 4, "[01] Tuesday", size=8.5, border=False, dq=1.2, dh=1.2)
  606. tb2.set_cell_text(row, 5, "星期二", size=8.5, border="right", dq=1.2, dh=1.2)
  607. tb2.set_cell_text(row, 6, "[01] Tuesday", size=8.5, border=False, dq=1.2, dh=1.2)
  608. tb2.set_cell_text(row, 7, "星期二", size=8.5, border=False, dq=1.2, dh=1.2)
  609. docx.set_page_column(5)
  610. docx.add_docx_component("make_docx_demo/word_component/component.docx")
  611. docx.end_page_column()
  612. if scanpage_format == 3:
  613. docx.add_page_section()
  614. @time_use
  615. def two_check_page(docx: Word, json_data, *args, **kwargs):
  616. def empty_filter_page(class_name, student_name, page_title, page_sub_title, t_datetime, word_data_list):
  617. page_sub_title = "词汇训练"
  618. if len(word_data_list) % 2 != 0:
  619. word_data_list.append("")
  620. tb = Table(docx, 1, 3, tb_name="头部三元素")
  621. tb.set_tb_colum_width(width=[40, 100, 100])
  622. tb.set_tb_colum_width(0, 100)
  623. tb.set_cell_text(0, 0, f"鲍利提分", border=False, size=16, bold=True, chinese_font_name="黑体")
  624. tb.set_cell_text(0, 1, f"{class_name}\n{student_name}", border=False, size=8, dh=2)
  625. tb.set_cell_text(0, 2, f"{page_title}\n{page_sub_title}", border=False, size=8, dh=2)
  626. docx.add_paragraph("请写出词义,再对照筛查表批改。词义顺序可互换;答案意思相符即可,不要求一字不差。批改结果誊抄到筛查表。", size=9)
  627. tb = Table(docx, rows=0, cols=4, tb_name="第一页筛查表")
  628. tb.set_all_border_fastly(xml=True, outside_side_border=True, outside_side_border_size=5)
  629. half_count = int(len(word_data_list) / 2)
  630. for index, row in enumerate(range(half_count)):
  631. first_word, second_word = word_data_list[row], word_data_list[row + half_count]
  632. cell3 = f"{index + 1 + half_count}. {second_word}" if second_word else ""
  633. cell4 = "□ ___________________________" if second_word else ""
  634. data = [f"{index + 1}. {first_word}", "□ ___________________________", cell3, cell4]
  635. tb.add_table_row_data_xml_fastly(data, font_size=[10.5, 9, 10.5, 9])
  636. tb.set_row_height(13.8)
  637. tb.set_table_width_xml([2124, 3257, 2140, 3257])
  638. blank_count = " " * 80
  639. p = docx.add_blank_paragraph(dq=5)
  640. p.add_run_to_p(f"{t_datetime} {page_title}-{page_sub_title}{blank_count}", size=8, chinese_font_name="仿宋", font_name="仿宋")
  641. docx.add_page_break()
  642. def filter_table_page(page_id, class_name, student_name, page_title, page_sub_title, t_datetime,
  643. foot_description, foot_description2, article_type, word_data_list2):
  644. page_sub_title = "词汇训练"
  645. if len(word_data_list2) % 2 != 0:
  646. word_data_list2.append(["", ""])
  647. tb = Table(docx, 1, 5, tb_name="头部五元素")
  648. tb.set_tb_colum_width(width=[80, 100, 120, 150, 70])
  649. tb.set_cell_text(0, 0, f"鲍利提分", border=False, size=16, bold=True, chinese_font_name="黑体")
  650. tb.set_cell_text(0, 1, f"{class_name}\n{student_name}", border=False, size=8)
  651. tb.set_cell_text(0, 2, f"{page_id}", border=False, size=16, dh=2, bold=True, font_name="黑体")
  652. tb.set_cell_text(0, 3, f"{page_title}\n{page_sub_title}", border=False, size=8)
  653. p_cell = tb.get_cell_paragraph(0, 4)
  654. p = ParagraphBase(p_cell)
  655. io_image = qrcode_maker(f"{page_id}")
  656. p.add_pic(io_image, width=Inches(0.6))
  657. io_image.close()
  658. pp = docx.add_blank_paragraph()
  659. pp.add_run_to_p("下述词汇相应的词义未掌握的请划掉,并将整个页面拍照给我们,以便记录词汇掌握数据。示例:comfort 4. 舒适,安逸", size=9)
  660. pp.add_rectangle('', x=540, y=10, width=55, height=0, boder_color='000000', shape_type='line')
  661. tb = Table(docx, rows=0, cols=4, tb_name="第二页筛查表")
  662. ## 1234竖着放
  663. total_row = int(len(word_data_list2) / 2)
  664. for row in range(total_row):
  665. spell1, meaning1 = word_data_list2[row]
  666. spell2, meaning2 = word_data_list2[total_row + row]
  667. cell3 = f"{spell2}" if spell2 else ""
  668. cell4 = f"{total_row + row + 1}. {meaning2}" if meaning2 else ""
  669. data = [f"{spell1}", f"{row + 1}. {meaning1}", cell3, cell4]
  670. tb.add_table_row_data_xml_fastly(data, font_size=[10.5, 9, 10.5, 9], alignment=['right', 'left', 'right', 'left'])
  671. tb.set_row_height(13.8)
  672. tb.set_table_width_xml([2124, 3257, 2140, 3257])
  673. docx.add_paragraph(f"{t_datetime} {page_title}-{page_sub_title}{foot_description}", size=8, chinese_font_name="仿宋",
  674. font_name="仿宋", dq=5)
  675. student_name = json_data.get("StudentInfo").get("StudentName", '')
  676. class_name = json_data.get("StudentInfo").get("ClassName", '').replace("词汇突击", "")
  677. t_datetime = time.strftime("%Y-%m-%d %H:%M", time.localtime())
  678. article_type = 1
  679. try:
  680. article_type = json_data['WordAndArticleContents'][0]['Articles'][0]['Category']
  681. except Exception as e:
  682. log_err_e(e, "学案类型不存在就取1,词汇突击里面只有阅读理解")
  683. """---------------------------------------------------------------------------------"""
  684. screening_scanPages = json_data['ScreeningScanPages']
  685. for index, page in enumerate(screening_scanPages, start=1):
  686. page_id = str(page['PageId']).rjust(11, "0")
  687. page_title = page['Title']
  688. page_sub_title = page['SubTitle']
  689. foot_description = page['FootDescription']
  690. foot_description2 = page['FootDescription2']
  691. word_data_list1 = []
  692. word_data_list2 = []
  693. for i in page['FilterTable']['Items']:
  694. word_data_list1.append(i['Spell'])
  695. word_data_list2.append([i['Spell'], i['Meaning']])
  696. filter_table_page(page_id, class_name, student_name, page_title, page_sub_title, t_datetime,
  697. foot_description, foot_description2, article_type, word_data_list2)
  698. if index != len(screening_scanPages):
  699. pass
  700. docx.add_page_break()
  701. def old_two_check_page(docx: Word, json_data, **kwargs):
  702. def empty_filter_page(class_name, student_name, page_title, page_sub_title, t_datetime, word_data_list):
  703. if len(word_data_list) % 2 != 0:
  704. word_data_list.append("")
  705. tb = Table(docx, 1, 3, tb_name="头部三元素")
  706. tb.set_tb_colum_width(width=[140, 100, 100])
  707. tb.set_cell_text(0, 0, f"鲍利提分", border=False, size=16, bold=True, chinese_font_name="黑体")
  708. tb.set_cell_text(0, 1, f"{class_name}\n{student_name}", border=False, size=8, dh=2)
  709. tb.set_cell_text(0, 2, f"{page_title}\n{page_sub_title}", border=False, size=8, dh=2)
  710. docx.add_paragraph("请写出词义,再对照筛查表批改。词义顺序可互换;答案意思相符即可,不要求一字不差。批改结果誊抄到筛查表。", size=9)
  711. tb = Table(docx, rows=0, cols=4, tb_name="第一页筛查表")
  712. tb.set_all_border_fastly(xml=True, outside_side_border=True, outside_side_border_size=5)
  713. half_count = int(len(word_data_list) / 2)
  714. for index, row in enumerate(range(half_count)):
  715. first_word, second_word = word_data_list[row], word_data_list[row + half_count]
  716. cell3 = f"{index + 1 + half_count}. {second_word}" if second_word else ""
  717. cell4 = "□ ___________________________" if second_word else ""
  718. data = [f"{index + 1}. {first_word}", "□ ___________________________", cell3, cell4]
  719. tb.add_table_row_data_xml_fastly(data, font_size=[10.5, 9, 10.5, 9])
  720. tb.set_row_height(13.8, first_row_h=6)
  721. tb.set_table_width_xml([2124, 3257, 2140, 3257])
  722. blank_count = " " * 80
  723. p = docx.add_blank_paragraph(dq=5)
  724. p.add_run_to_p(f"{t_datetime} {page_title}-{page_sub_title}{blank_count}", size=8, chinese_font_name="仿宋", font_name="仿宋")
  725. docx.add_page_break()
  726. def filter_table_page(page_id, class_name, student_name, page_title, page_sub_title, t_datetime,
  727. foot_description, foot_description2, article_type, word_data_list2):
  728. if len(word_data_list2) % 2 != 0:
  729. word_data_list2.append(["", ""])
  730. tb = Table(docx, 1, 5, tb_name="头部五元素")
  731. tb.set_tb_colum_width(width=[80, 100, 120, 150, 70])
  732. tb.set_cell_text(0, 0, f"鲍利提分", border=False, size=16, bold=True, chinese_font_name="黑体")
  733. tb.set_cell_text(0, 1, f"{class_name}\n{student_name}", border=False, size=8)
  734. tb.set_cell_text(0, 2, f"{page_id}", border=False, size=16, dh=2, bold=True, font_name="黑体")
  735. tb.set_cell_text(0, 3, f"{page_title}\n{page_sub_title}", border=False, size=8)
  736. p_cell = tb.get_cell_paragraph(0, 4)
  737. p = ParagraphBase(p_cell)
  738. page_id = int(page_id)
  739. io_image = qrcode_maker(f"{page_id}")
  740. p.add_pic(io_image, width=Inches(0.6))
  741. io_image.close()
  742. pp = docx.add_blank_paragraph()
  743. p_base = ParagraphBase(pp)
  744. p_base.p.add_run_to_p("请在需要加强学习的词义前方框中划线,两头各超出1毫米为宜(示例:", size=9)
  745. p_base.p.add_pic("make_docx_demo/static/line_example.png", width=Inches(0.8))
  746. p_base.p.add_run_to_p(" );请保持本表整洁并交回。", size=9)
  747. tb = Table(docx, rows=0, cols=4, tb_name="第二页筛查表")
  748. ## 1234竖着放
  749. total_row = int(len(word_data_list2) / 2)
  750. for row in range(total_row):
  751. spell1, meaning1 = word_data_list2[row]
  752. spell2, meaning2 = word_data_list2[total_row + row]
  753. cell1 = f"{row + 1}. {spell1}" if spell1 else ""
  754. cell2 = f"□ {meaning1}" if meaning1 else ""
  755. cell3 = f"{total_row + row + 1}. {spell2}" if spell2 else ""
  756. cell4 = f"□ {meaning2}" if meaning2 else ""
  757. data = [cell1, cell2, cell3, cell4]
  758. tb.add_table_row_data_xml_fastly(data, font_size=[10.5, 9, 10.5, 9])
  759. tb.set_all_border_fastly(xml=True, outside_side_border=True, outside_side_border_size=5)
  760. tb.set_row_height(13.6, first_row_h=6)
  761. tb.set_table_width_xml([2124, 3257, 2140, 3257])
  762. if article_type == 1:
  763. docx.add_paragraph(f"{t_datetime} {page_title}-{page_sub_title}{foot_description}", size=8, chinese_font_name="仿宋",
  764. font_name="仿宋", dq=5)
  765. docx.add_paragraph(foot_description2, align="right", size=8, chinese_font_name="仿宋")
  766. else:
  767. docx.add_paragraph(f"{t_datetime} {page_title}-{page_sub_title}{foot_description}", size=8, chinese_font_name="仿宋",
  768. font_name="仿宋", dq=5)
  769. student_name = json_data.get("StudentInfo").get("StudentName", '')
  770. class_name = json_data.get("StudentInfo").get("ClassName", '')
  771. t_datetime = time.strftime("%Y-%m-%d %H:%M", time.localtime())
  772. article_type = json_data['WordAndArticleContents'][0]['Articles'][0]['Category']
  773. is_add_empty_filter_page = json_data['Config']['AddEmptyFilterPage']
  774. """---------------------------------------------------------------------------------"""
  775. for index, page in enumerate(json_data['ScreeningScanPages'], start=1):
  776. page_id = str(page['PageId']).rjust(11, "0")
  777. if index >= 2:
  778. docx.add_page_break()
  779. page_title = page['Title']
  780. page_sub_title = page['SubTitle']
  781. foot_description = page['FootDescription']
  782. foot_description2 = page['FootDescription2']
  783. word_data_list1 = []
  784. word_data_list2 = []
  785. item_list: list = page['FilterTable']['Items']
  786. item_count = len(item_list)
  787. if item_count < 100:
  788. item_list.extend([{"Spell": "", "Meaning": ""} for _ in range(100 - item_count)])
  789. for i in page['FilterTable']['Items']:
  790. word_data_list1.append(i['Spell'])
  791. word_data_list2.append([i['Spell'], i['Meaning']])
  792. if is_add_empty_filter_page:
  793. empty_filter_page(class_name, student_name, page_title, page_sub_title, t_datetime, word_data_list1)
  794. filter_table_page(page_id, class_name, student_name, page_title, page_sub_title, t_datetime,
  795. foot_description, foot_description2, article_type, word_data_list2)
  796. @time_use
  797. def other(docx, json_data, *args, **kwargs):
  798. sections = docx.doc.sections
  799. for section in sections[:-1]:
  800. section.top_margin = Inches(0.3)
  801. section.bottom_margin = Inches(0.4)
  802. section.left_margin = Inches(0.8)
  803. section.right_margin = Inches(0.8)
  804. section.footer_distance = 180000
  805. sections[-1].top_margin = Inches(0.1)
  806. sections[-1].bottom_margin = Inches(0.1)
  807. sections[-1].left_margin = Inches(0.5)
  808. sections[-1].right_margin = Inches(0.5)
  809. header_maker(docx, json_data)
  810. def start_make_word(json_data, document_format, scanpage_format):
  811. parent_path = "make_docx_demo/file_result/"
  812. if not os.path.exists(parent_path):
  813. os.makedirs(parent_path)
  814. try:
  815. exercise_id = json_data['ExerciseId']
  816. docx = Word(save_file_name=f"{parent_path}{exercise_id}.docx",
  817. start_template_name="make_docx_demo/word_component/start_template.docx")
  818. section_1(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  819. section_4(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  820. for exercise_json in json_data['WordAndArticleContents']:
  821. section_4_1(docx=docx, json_data=exercise_json, scanpage_format=scanpage_format)
  822. section_5(docx=docx, json_data=exercise_json, scanpage_format=scanpage_format)
  823. section_6(docx=docx, json_data=exercise_json, scanpage_format=scanpage_format)
  824. section_7(docx=docx, json_data=exercise_json, scanpage_format=scanpage_format)
  825. section_9(docx=docx, json_data=exercise_json, scanpage_format=scanpage_format)
  826. if scanpage_format == 1:
  827. two_check_page(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  828. old_two_check_page(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  829. elif scanpage_format == 2:
  830. section_10(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  831. elif scanpage_format == 3:
  832. section_10(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  833. two_check_page(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  834. other(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  835. docx.save_docx()
  836. if document_format == 1:
  837. return f"{parent_path}{exercise_id}.docx"
  838. else:
  839. convert_word_to_pdf(f"{parent_path}{exercise_id}")
  840. return f"{parent_path}{exercise_id}.pdf"
  841. except Exception as e:
  842. log_err_e(e)
  843. if __name__ == '__main__':
  844. import os
  845. t = time.time()
  846. os.chdir("..")
  847. start_make_word(test_json1, 1, 1)
  848. print(time.time() - t)