main_word.py 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. # -*- coding: UTF-8 -*-
  2. import time
  3. import re
  4. import math
  5. from io import BytesIO
  6. from random import randint, shuffle
  7. from threading import Thread
  8. from docx_base import Word, Table, hex_to_rgb, rgb_to_hex, ParagraphBase
  9. from docx.shared import Pt, Inches, Cm, RGBColor
  10. from docx.enum.text import WD_COLOR_INDEX
  11. from make_docx_demo.data import *
  12. from make_docx_demo.docx_other_func import time_use, qrcode_maker, get_weekday, make_chart
  13. from tools.loglog import logger, log_err_e
  14. from make_docx_demo.word2pdf import convert_word_to_pdf
  15. num_dict = {1: "❶", 2: "❷", 3: "❸", 4: "❹", 5: "❺", 6: "❻", 7: "❼", 8: "❽", 9: "❾",
  16. 10: "❿", 11: "⓫", 12: "⓬", 13: "⓭", 14: "⓮", 15: "⓯", 16: "⓰", 17: "⓱", 18: "⓲", 19: "⓳", 20: "⓴"}
  17. @time_use
  18. def header_maker(docx: Word, json_data):
  19. exercise_id = str(json_data.get("ExerciseId", "")).rjust(11, "0")
  20. exercise_title = json_data.get("ExerciseTitle", "")
  21. exercise_level = json_data['StudentInfo']['StudentStudy']['ReadingLevel']
  22. student_name = json_data.get("StudentInfo").get("StudentName", '')
  23. class_name = json_data.get("StudentInfo").get("ClassName", '')
  24. t_date = time.strftime("%Y-%m-%d", time.localtime())
  25. t_weekday = get_weekday()
  26. t_time = time.strftime("%H:%M:%S", time.localtime())
  27. for i in range(2, len(docx.doc.sections) - 1):
  28. tb_header = docx.add_header_table(rows=1, cols=5, section_index=i, tb_name="页眉表格")
  29. tb_header.set_cell_text(0, 0, "春笋英语", bold=True, size=16, color=(220, 220, 220), border=False, chinese_font_name="黑体")
  30. tb_header.set_cell_text(0, 1, f"{class_name}\n{student_name}", size=8, border=False, color=(220, 220, 220))
  31. tb_header.set_cell_text(0, 2, f"{exercise_title}\n{exercise_level}级", size=8, border=False, color=(220, 220, 220))
  32. tb_header.set_cell_text(0, 3, f"{exercise_id}", bold=True, size=24, border=False, color=(220, 220, 220))
  33. tb_header.set_cell_text(0, 4, f"{t_date}\n{t_weekday}\n{t_time}", size=8, border=False, color=(220, 220, 220))
  34. tb_header.set_tb_colum_width(width=[100, 70, 70, 150, 80])
  35. target_section = docx.doc.sections[-1]
  36. target_section.header.is_linked_to_previous = False
  37. for paragraph in target_section.header.paragraphs:
  38. paragraph.clear()
  39. target_section.header_distance = 0
  40. target_section.footer_distance = 280000
  41. @time_use
  42. def sub_title_maker(docx: Word, main_title, sub_title_name1, sub_title_name2='春笋学习,高效学习专家'):
  43. p = docx.add_blank_paragraph()
  44. line_width = 205
  45. main_rect_x = line_width + 10
  46. main_rect_width = 150
  47. right_line_x = main_rect_x + main_rect_width + 10
  48. p.add_rectangle(main_title, x=main_rect_x, y=4, fill_color="000000", width=main_rect_width, height=48, font_color="ffffff",
  49. font_size=18)
  50. p.add_rectangle("", x=0, y=50, boder_color="808080", width=line_width, height=2)
  51. p.add_rectangle("", x=right_line_x, y=50, boder_color="808080", width=line_width, height=2)
  52. p.add_rectangle(f"【{sub_title_name1}】", x=0, y=20, width=line_width, height=40, font_size=8, chinese_font="宋体")
  53. p.add_rectangle(sub_title_name2, x=right_line_x, y=20, width=line_width, height=40, font_color="808080", font_size=8,
  54. chinese_font="宋体")
  55. docx.add_blank_paragraph()
  56. docx.add_blank_paragraph()
  57. docx.add_blank_paragraph()
  58. @time_use
  59. def section_1(docx: Word, json_data, *args, **kwargs):
  60. exercise_id = str(json_data.get("ExerciseId", "")).rjust(11, "0")
  61. student_name = json_data.get("StudentInfo").get("StudentName", '')
  62. t_date_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
  63. reading_speed = json_data['StudentInfo']['StudentStudy']['ReadingSpeed']
  64. reading_accuracy = json_data['StudentInfo']['StudentStudy']['ReadingAccuracy']
  65. reading_level = json_data['StudentInfo']['StudentStudy']['ReadingLevel']
  66. chart_width = 5.4
  67. all_chart = json_data['StudentInfo']['StudentStudy']['ChartData']
  68. reading_speed_chart = all_chart["ReadingSpeed"]
  69. reading_accuracy_chart = all_chart["ReadingAccuracy"]
  70. reading_difficult_chart = all_chart["ReadingDifficulties"]
  71. reading_speed_x_data = reading_speed_chart['XAxis']
  72. reading_speed_sub_title = reading_speed_chart['Legend']
  73. reading_speed_y_datas = [i['Data'] for i in reading_speed_chart['Series']]
  74. reading_accuracy_x_data = reading_accuracy_chart['XAxis']
  75. reading_accuracy_sub_title = reading_accuracy_chart['Legend']
  76. reading_accuracy_y_datas = [i['Data'] for i in reading_accuracy_chart['Series']]
  77. reading_difficult_x_data = reading_difficult_chart['XAxis']
  78. reading_difficult_sub_title = reading_difficult_chart['Legend']
  79. reading_difficult_y_datas = [i['Data'] for i in reading_difficult_chart['Series']]
  80. "开始版面-------------------------------------------------"
  81. docx.add_paragraph("春笋英语 减负增效", size=24, bold=True, align="center", dq=20, dh=10)
  82. docx.add_paragraph("个性化学案", size=42, bold=True, chinese_font_name="黑体", align="center", dq=10, dh=20)
  83. p = docx.add_blank_paragraph(align="center")
  84. p.add_pic("make_docx_demo/static/logo.png", width=3)
  85. tb1 = Table(docx, rows=1, cols=3)
  86. tb1.set_cell_text(row=0, column=1, cell_text=f"姓名:{student_name} 编号:{exercise_id}", set_all_cell=False, color="CCCCCC")
  87. tb1.set_tb_colum_width(width=[100, 301, 100])
  88. tb2 = Table(docx, rows=1, cols=3, tb_name="三张图表")
  89. tb2.set_cell_text(0, 0, f"阅读速度\n{reading_speed}", bold=True, dq=10, dh=10)
  90. tb2.set_cell_text(0, 1, f"阅读准确率%\n{reading_accuracy}", bold=True, dq=10, dh=10)
  91. tb2.set_cell_text(0, 2, f"阅读等级\n{reading_level}", bold=True, dq=10, dh=10)
  92. tb2.set_tb_colum_width(width=[167, 167, 167])
  93. docx.add_blank_paragraph()
  94. tb3 = Table(docx, rows=1, cols=3, border=True)
  95. tb3.set_tb_colum_width(width=[167, 167, 167])
  96. p1 = tb3.get_cell_paragraph(0, 0, dq=15, dh=15)
  97. run1 = ParagraphBase(p1)
  98. chart1_io = make_chart(x_axis_data=reading_speed_x_data, y_axis_datas=reading_speed_y_datas, title="阅读速度",
  99. sub_title_list=reading_speed_sub_title)
  100. run1.add_pic(chart1_io, width=chart_width)
  101. chart1_io.close()
  102. p2 = tb3.get_cell_paragraph(0, 1, dq=15, dh=15)
  103. run2 = ParagraphBase(p2)
  104. chart2_io = make_chart(x_axis_data=reading_accuracy_x_data, y_axis_datas=reading_accuracy_y_datas, title="阅读准确率",
  105. sub_title_list=reading_accuracy_sub_title)
  106. run2.add_pic(chart2_io, width=chart_width)
  107. chart2_io.close()
  108. p3 = tb3.get_cell_paragraph(0, 2, dq=15, dh=15)
  109. run3 = ParagraphBase(p3)
  110. chart3_io = make_chart(x_axis_data=reading_difficult_x_data, y_axis_datas=reading_difficult_y_datas, title="阅读难度",
  111. sub_title_list=reading_difficult_sub_title)
  112. run3.add_pic(chart3_io, width=chart_width)
  113. chart3_io.close()
  114. docx.add_blank_paragraph()
  115. tb4 = Table(docx, rows=5, cols=5, border=True, tb_name="自主复习记录")
  116. tb4.set_table_width_xml([2000, 3000, 2000, 2000, 2000])
  117. first_cell = tb4.get_cell(0, 0)
  118. last_cell = tb4.get_cell(0, 4)
  119. first_cell.merge(last_cell)
  120. first_cell = tb4.get_cell(4, 0)
  121. last_cell = tb4.get_cell(4, 4)
  122. first_cell.merge(last_cell)
  123. tb4.set_cell_text(0, 0, "自主复习记录", size=14, bold=True, color=(230, 230, 230), set_all_cell=False)
  124. tb4.set_cell_text(1, 0, "模块", size=14, bold=True, color=(244, 244, 244), set_all_cell=False)
  125. tb4.set_cell_text(1, 1, "复习建议", size=14, bold=True, color=(244, 244, 244), set_all_cell=False)
  126. tb4.set_cell_text(1, 2, "10.1", size=14, bold=True, color=(244, 244, 244), set_all_cell=False)
  127. tb4.set_cell_text(1, 3, "10.4", size=14, bold=True, color=(244, 244, 244), set_all_cell=False)
  128. tb4.set_cell_text(1, 4, "10.7", size=14, bold=True, color=(244, 244, 244), set_all_cell=False)
  129. tb4.set_cell_text(2, 0, "词汇学习", size=14, bold=True, set_all_cell=False)
  130. tb4.set_cell_text(2, 1, "将单词、词义、例句朗读2遍", size=10, set_all_cell=False, align="left")
  131. tb4.set_cell_text(3, 0, "阅读理解", size=14, bold=True, set_all_cell=False)
  132. tb4.set_cell_text(3, 1, "1.文章朗读一遍\n2.口头翻译黑体词所在的句子", size=10, align="left")
  133. tb4.set_cell_text(4, 0, "备注:完成相应复习后在对应格子中打√", size=10, bold=True, align="right")
  134. docx.add_paragraph(f"生成日期: {t_date_time}", align="center", dq=20)
  135. docx.add_page_section()
  136. @time_use
  137. def section_2(docx: Word, json_data, *args, **kwargs):
  138. docx.add_paragraph("致同学,家长们的一封信", bold=True, chinese_font_name="黑体", size=16, align="center", dq=5, dh=15)
  139. docx.add_paragraph("各位同学、家长,你们好!", bold=True, size=12)
  140. p1 = docx.add_blank_paragraph(dq=10, dh=10)
  141. p1.add_run_to_p("关于我们:", chinese_font_name="黑体", bold=True, size=10)
  142. p1.add_run_to_p("北京云知学科技有限公司是专注于", size=10)
  143. p1.add_run_to_p("英语课堂信息化研究的高新技术企业", underline=True, size=10)
  144. p1.add_run_to_p(",是教育部“数字校园综合解决方案”推荐单位。旗下品牌春笋英语是全国首家纸面化智能英语教学系统,合作学校超1000家,助力超50万名学生提升英语成绩。"
  145. "春笋英语个性化学案,落实双减政策,根据每个学生的实际水平,一对一定制学案内容,实现减负、增效。",
  146. size=10)
  147. docx.add_blank_paragraph()
  148. p2 = docx.add_blank_paragraph(dq=10, dh=5)
  149. p2.add_pic(pic_path="make_docx_demo/static/pen.png", width=0.5, underline=True)
  150. p2.add_run_to_p(" 为什么学好英语,而不是改学日语等小语种:", underline=True, size=10)
  151. p3 = docx.add_blank_paragraph(dq=5, dh=5)
  152. p3.add_run_to_p("1.专业限制:", bold=True, size=10, chinese_font_name="黑体")
  153. p3.add_run_to_p("学习小语种在高考志愿填报时会有专业限制。例如,军校、警校和多数科技类专业通常只招收考英语的学生。\n", size=10)
  154. p3.add_run_to_p("2.利于学业发展:", bold=True, size=10, chinese_font_name="黑体")
  155. p3.add_run_to_p("大学毕业及考研都需要英语,考小语种进大学后会更吃力。\n", size=10)
  156. p3.add_run_to_p("3.就业面窄:", bold=True, size=10, chinese_font_name="黑体")
  157. p3.add_run_to_p("大多数就业机会以及公务员考试往往都有英语要求。\n", size=10)
  158. p3.add_run_to_p("4.英语并不难:", bold=True, size=10, chinese_font_name="黑体")
  159. p3.add_run_to_p("只要方法得当,半年时间就可以显著提高。\n", size=10)
  160. p2 = docx.add_blank_paragraph(dq=10, dh=5)
  161. p2.add_pic(pic_path="make_docx_demo/static/pen.png", width=0.5, underline=True)
  162. p2.add_run_to_p(" 为什么学不好英语:方法不对", underline=True, size=10)
  163. p3 = docx.add_blank_paragraph(dq=5, dh=5)
  164. p3.add_run_to_p("1.单词+语法≠英语:", bold=True, size=10, chinese_font_name="黑体")
  165. p3.add_run_to_p("单纯的记忆单词和语法规则并不足以理解英语文章,更不足以写出流畅的作文。\n", size=10)
  166. p3.add_run_to_p("2.钻研英语考试≠学英语:", bold=True, size=10, chinese_font_name="黑体")
  167. p3.add_run_to_p("考试技巧并不能提高英语水平,只能造成得分虚高的假象,使英语学习越来越缺乏后劲,分数越学越低。\n", size=10)
  168. p3.add_run_to_p("3.英语是技能,用的多了就会了:", bold=True, size=10, chinese_font_name="黑体")
  169. p3.add_run_to_p("就像每个英国人都会说英语一样,每个中国人也都可以学好英语。\n", size=10)
  170. p2 = docx.add_blank_paragraph(dq=10, dh=5)
  171. p2.add_pic(pic_path="make_docx_demo/static/pen.png", width=0.5, underline=True)
  172. p2.add_run_to_p(" 怎样学好英语:", underline=True, size=10)
  173. p3 = docx.add_blank_paragraph(dq=5, dh=5)
  174. p3.add_run_to_p("1.大量阅读:", bold=True, size=10, chinese_font_name="黑体")
  175. p3.add_run_to_p("足量的阅读是掌握英语“技能”的必由之路。\n", size=10)
  176. p3.add_run_to_p("2.大量难度适宜的阅读:", bold=True, size=10, chinese_font_name="黑体")
  177. p3.add_run_to_p(
  178. "多数同学看不懂文章只能猜答案,即使做了阅读题也没有真正读文章,所以阅读材料难度适宜非常关键,“看得懂”才能真正实现“大量的阅读”。\n",
  179. size=10)
  180. p3.add_run_to_p("3.在阅读过程中自动掌握单词,领悟语法:", bold=True, size=10, chinese_font_name="黑体")
  181. p3.add_run_to_p("阅读量足够大,单词就自然掌握了,语法即使不知道概念也能理解其含义。\n", size=10)
  182. p3.add_run_to_p("4.四个月为一个周期:", bold=True, size=10, chinese_font_name="黑体")
  183. p3.add_run_to_p("几十万的春笋英语学员的经历表明,只要听话照做,平均四个月就能", size=10)
  184. p3.add_run_to_p("提升 20-30分", bold=True, size=10, chinese_font_name="黑体")
  185. p3.add_run_to_p("。\n", size=10)
  186. p2 = docx.add_blank_paragraph(dq=10, dh=5)
  187. p2.add_pic(pic_path="make_docx_demo/static/pen.png", width=0.5, underline=True)
  188. p2.add_run_to_p(" 春笋英语践行的理念:", underline=True, size=10)
  189. p3 = docx.add_blank_paragraph(dq=5, dh=5)
  190. p3.add_run_to_p("要抓紧,别着急,不走捷径,踏实看懂每句话,提分就是水到渠成。\n", size=10)
  191. p3.add_run_to_p("树立信心,有方法,有效果,有效率,100天脱胎换骨。", size=10)
  192. docx.add_blank_paragraph(dq=2, dh=2)
  193. docx.add_paragraph("北京云知学科技有限公司", align="right", size=10)
  194. docx.add_page_section()
  195. @time_use
  196. def section_3(docx: Word, json_data, *args, **kwargs):
  197. docx.add_paragraph("春笋英语学案学习流程", chinese_font_name="黑体", bold=True, align="center", size=16)
  198. p1 = docx.add_blank_paragraph(dq=10)
  199. p1.add_run_to_p("1.认读\n", bold=True, size=10, chinese_font_name="黑体")
  200. p1.add_run_to_p("按顺序朗读生词表两遍。\n", size=10)
  201. p1.add_run_to_p("(1)用红笔在不会的单词序号上打星号,增加记忆。\n", size=10)
  202. p1.add_run_to_p("(2)朗读例句,不认识的部分参照译文理解。\n", size=10)
  203. p1.add_run_to_p("(3)不会念的单词拼读音标;音标不会拼读的,申请音标课,约5个小时即可。\n", size=10)
  204. p2 = docx.add_blank_paragraph()
  205. p2.add_run_to_p("2.速记\n", bold=True, size=10, chinese_font_name="黑体")
  206. p2.add_run_to_p("(1)按顺序抄写,用黑笔完成,会的单词可以直接默写,不会的单词对照生词表进行抄写。提高效率,节约时间,不必犹豫纠结。\n", size=10)
  207. p2.add_run_to_p("(2)抄写过程中尽量朗读或默读,不必额外增加抄写次数,切勿死记硬背。\n", size=10)
  208. p3 = docx.add_blank_paragraph()
  209. p3.add_run_to_p("3.例句练习\n", bold=True, size=10, chinese_font_name="黑体")
  210. p3.add_run_to_p("翻译例句,可参考学生词表例句译文,在括号内写出单词汉语意思。\n", size=10)
  211. p4 = docx.add_blank_paragraph()
  212. p4.add_run_to_p("4.阅读\n", bold=True, size=10, chinese_font_name="黑体")
  213. p4.add_run_to_p("(1)认清阅读与做题的关系:阅读是为了提高文本敏感度,做题只是为了检验阅读质量。\n", size=10)
  214. p4.add_run_to_p(
  215. "不要为加快答题而跳读略读,不要先读题目再回原文查找答案,逐字逐句读完全文再做题,日常学案训练不要利用答题技巧,作答时要回到原文确认内容,养成良好答题习惯。\n",
  216. bold=True, size=10, chinese_font_name="黑体")
  217. p4.add_run_to_p("(2)读轻松愉快的文章才是难度适当的,如果阅读吃力,直接申请调整难度(", size=10)
  218. p4.add_run_to_p("可在筛查反馈表贴便贴留言", bold=True, size=10, chinese_font_name="黑体")
  219. p4.add_run_to_p("),不要勉强,提高时间利用率。\n", size=10)
  220. p4.add_run_to_p("(3)遇到生词,划线标记,事后查字典,把意思写在右侧标注区,不要写在原文上;生词太多的文章可以放弃,不要让查字典成为负担。\n",
  221. size=10)
  222. p4.add_run_to_p("(4)黑体字、斜体字不认识,可以当场查阅生词表和标注。\n", size=10)
  223. p4.add_run_to_p("(5)必须将做题开始和结束时间填写上,精确到秒。\n", size=10)
  224. p4.add_run_to_p("(6)做题过程中,自己对于答案不理解、不确定的题目要标注出来。\n", size=10)
  225. p5 = docx.add_blank_paragraph()
  226. p5.add_run_to_p("5.核对答案\n", bold=True, size=10, chinese_font_name="黑体")
  227. p5.add_run_to_p("红笔批改。正常应该全对,允许因疏忽偶尔错一题。\n", size=10)
  228. p6 = docx.add_blank_paragraph()
  229. p6.add_run_to_p("6.划筛查表、报告阅读数据\n", bold=True, size=10, chinese_font_name="黑体")
  230. p6.add_run_to_p("和摸底一样的流程,", size=10)
  231. p6.add_run_to_p("筛查表很重要,务必严格对待,实事求是,否则下一份学案学习内容会有偏差;", bold=True, size=10, chinese_font_name="黑体")
  232. p6.add_run_to_p("务必填涂阅读用时和答对题数。\n", size=10)
  233. p7 = docx.add_blank_paragraph()
  234. p7.add_run_to_p("7.交卷\n", bold=True, size=10, chinese_font_name="黑体")
  235. p7.add_run_to_p("学案做完后,将学案的最后一页筛查反馈表反馈给老师。\n", size=10)
  236. p8 = docx.add_blank_paragraph()
  237. p8.add_run_to_p("8.回顾\n", bold=True, size=10, chinese_font_name="黑体")
  238. p8.add_run_to_p("回到学案第一页封面,在规定的时间内回顾学案内容并在自主复习记录表中登记(自主复习表在封面位置)。", size=10)
  239. docx.add_page_section()
  240. @time_use
  241. def section_4(docx: Word, json_data, *args, **kwargs):
  242. student_name = json_data.get("StudentInfo").get("StudentName", '')
  243. title_info = "\n".join(json_data.get("Title"))
  244. docx.add_paragraph(f"{student_name} 同学:", align="center", bold=True, dq=5, dh=5)
  245. p1 = docx.add_blank_paragraph()
  246. p1.add_run_to_p(title_info, size=10)
  247. sub_title_maker(docx, "词汇精准学", "智能定制专属词汇,轻松学习")
  248. tb = Table(docx, 1, 1, border=True, tb_name="词汇精准学")
  249. tb.set_tb_colum_width(0, 460)
  250. tb.set_cell_text(0, 0, "按顺序朗读生词表两遍。\n(1)用红笔在不会的单词序号上打星号,增加记忆。 (2)朗读例句,不认识的部分参照译文理解。",
  251. align="left", size=10, dq=10, dh=10)
  252. docx.add_blank_paragraph()
  253. @time_use
  254. def section_4_1(docx: Word, json_data, *args, **kwargs):
  255. def insert_content(row, col, data, qrcode_result: dict):
  256. cell_outside = tb_outside.get_cell(row, col, delete_default_para=True)
  257. tb_inside = Table(cell_outside, rows=5, cols=3, tb_name="内部内容")
  258. tb_inside.merge_cell(0, 0, 0, 1)
  259. tb_inside.merge_cell(1, 0, 1, 1)
  260. tb_inside.merge_cell(0, 2, 1, 2)
  261. tb_inside.merge_cell(2, 0, 2, 2)
  262. tb_inside.merge_cell(3, 0, 3, 2)
  263. tb_inside.merge_cell(4, 0, 4, 2)
  264. num_calucate = 2 * row + 1 if col == 0 else 2 * row + 2
  265. p = ParagraphBase(tb_inside.get_cell_paragraph(0, 0, align="left"))
  266. p.add_run_to_p(num_dict[num_calucate], bold=True, size=22, font_name="MS Gothic")
  267. p.add_run_to_p(' ' + data[0], bold=True, size=20)
  268. tb_inside.set_cell_text(row=1, column=0, cell_text=data[1] + " " + data[2], border=False, size=10, align="left",
  269. bk_color=(240, 240, 240))
  270. image_io: BytesIO = qrcode_result.get(data[9], "")
  271. if image_io:
  272. cell_p = tb_inside.get_cell_paragraph(0, 2, dq=5)
  273. p_base = ParagraphBase(cell_p)
  274. p_base.add_pic(image_io, width=1.5)
  275. image_io.close()
  276. cell_p = tb_inside.get_cell_paragraph(2, 0, align="left")
  277. cell_p_1 = ParagraphBase(cell_p)
  278. cell_p_1.add_run_to_p(data[3], size=10, bold=True)
  279. cell_p_1.add_run_to_p(" " + data[4], size=8)
  280. cell_p = tb_inside.get_cell_paragraph(3, 0, align="left")
  281. cell_p_1 = ParagraphBase(cell_p)
  282. cell_p_1.add_run_to_p(data[5], size=10, bold=True)
  283. cell_p_1.add_run_to_p(" " + data[6], size=8)
  284. cell_p = tb_inside.get_cell_paragraph(4, 0, align="left")
  285. cell_p_1 = ParagraphBase(cell_p)
  286. cell_p_1.add_run_to_p(data[7], size=10, bold=True)
  287. cell_p_1.add_run_to_p(" " + data[8], size=8)
  288. properties_chinese_map = {"adj": "形容词", "n": "名词", "interj": "感叹词", "conj": "连词", "num": "数字", "art": "冠词",
  289. "pron": "代词", "adv": "副词", "prep": "介词", "v": "动词"}
  290. strange_words_data = []
  291. strange_words = json_data.get('StrangeWords')
  292. qrcode_thread = []
  293. qrcode_result = {}
  294. for item in strange_words:
  295. spell = item['Spell']
  296. word_id = item['WordId']
  297. en = "" if not item.get("SymbolsEn", "") else item.get("SymbolsEn")
  298. am = "" if not item.get("SymbolsAm", "") else item.get("SymbolsAm")
  299. symbols_en = "英" + f'[{en}]'
  300. symbols_am = "美" + f'[{am}]'
  301. tts_url = f"https://dcjxb.yunzhixue.cn/exercise/word?id={word_id}"
  302. t = Thread(target=qrcode_maker, args=(tts_url, qrcode_result))
  303. qrcode_thread.append(t)
  304. t.start()
  305. word_properties = " ".join([properties_chinese_map.get(i, "") for i in item['WordProperties']])
  306. word_meanings = item.get('Meaning', "")
  307. word_changes = ";".join([s["Type"] + ":" + s["Spell"] for s in item["WordChanges"]])
  308. if item['Sentences']:
  309. sentences = item['Sentences'][0]['English'] + '\n' + item['Sentences'][0]['Chinese']
  310. else:
  311. sentences = ""
  312. single_word_tuple = (spell, symbols_en, symbols_am, word_properties, word_meanings,
  313. "词汇变形", word_changes, "例句", sentences, tts_url)
  314. strange_words_data.append(single_word_tuple)
  315. rows = math.ceil(len(strange_words_data) / 2)
  316. tb_outside = Table(docx, rows=rows, cols=2, tb_name="外层框架")
  317. tb_outside.set_tb_colum_width(width=[230, 230])
  318. for t in qrcode_thread:
  319. t.join()
  320. for row in range(rows):
  321. for col in range(2):
  322. try:
  323. data_item = strange_words_data.pop(0)
  324. insert_content(row, col, data_item, qrcode_result)
  325. except IndexError:
  326. break
  327. docx.add_page_section()
  328. @time_use
  329. def section_5(docx: Word, json_data, *args, **kwargs):
  330. copy_word_list = [i['Meaning'] for i in json_data.get('StrangeWords')]
  331. random_copy_word_list = copy_word_list * 3
  332. shuffle(random_copy_word_list)
  333. first_copy_word_list = copy_word_list.copy()
  334. copy_word_list_add_num = [f"{i} ({idx})" for idx, i in enumerate(first_copy_word_list, start=1)]
  335. shuffle(copy_word_list_add_num)
  336. total_copy_word_list = copy_word_list_add_num + random_copy_word_list
  337. sub_title_maker(docx, "单词高效记", "会读会写才算真学会")
  338. tb = Table(docx, 1, 1, tb_name="SuperMemo 速记", border=True)
  339. tb.set_tb_colum_width(0, 460)
  340. text = ["请先按照浅色水印显示的助记音节小声朗读,并在浅色水印上摹写,音节分隔点不用抄写。\n",
  341. "请在横线上写下对应单词,每格写一遍,尽量默写,默写不出的,可查阅生词表;\n",
  342. "书写时保持工整;每写完一个单词小声念一遍词义与单词。\n"]
  343. cell_p = tb.get_cell_paragraph(0, 0, align="left")
  344. p = ParagraphBase(cell_p)
  345. p.add_run_to_p(" SuperMemo 速记\n", size=16, bold=True, )
  346. for t in text:
  347. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  348. p.add_run_to_p(t, size=10)
  349. docx.add_blank_paragraph()
  350. total_count = len(total_copy_word_list)
  351. half_count = int(total_count / 2)
  352. tb2 = Table(docx, half_count + 1, 4, tb_name="SuperMemo 速记下面的单词")
  353. for row in range(total_count):
  354. data = total_copy_word_list[row]
  355. if row < half_count:
  356. tb2.set_cell_text(row, 0, data, size=9, align="right", border=False, dq=2.5, dh=2)
  357. tb2.set_cell_text(row, 1, str(row + 1) + "." + "_" * 20, size=9, align="left", border=False, dq=2.5, dh=2)
  358. else:
  359. tb2.set_cell_text(row - half_count, 2, data, size=9, align="right", border=False, dq=2.5, dh=2)
  360. tb2.set_cell_text(row - half_count, 3, str(row + 1) + "." + "_" * 20, size=9, align="left", border=False, dq=2.5, dh=2)
  361. tb2.set_tb_colum_width(width=[120, 110] * 2)
  362. docx.add_page_section()
  363. @time_use
  364. def section_6(docx: Word, json_data, *args, **kwargs):
  365. example_sentence = [f"{index}. {i['Sentences'][0]['English']} ({i['Spell']})" for index, i in
  366. enumerate(json_data['StrangeWords'], start=1) if i['Sentences']]
  367. sub_title_maker(docx, "例句填填看", "记词义,练拼写,学的快")
  368. tb = Table(docx, 1, 1, tb_name="例句填填看", border=True)
  369. tb.set_tb_colum_width(0, 460)
  370. text = ["请在横线上写下单词在例句中的词义,若想不起来,可随时到例句答案表中查看。\n",
  371. "参阅过答案的例句,请在句前的“□”中标记问号,以便复习回顾。\n",
  372. "单词有多个意思的,应只填写适合语境的意思。"]
  373. cell_p = tb.get_cell_paragraph(0, 0, align="left", dq=10, dh=10)
  374. p = ParagraphBase(cell_p)
  375. for t in text:
  376. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  377. p.add_run_to_p(t, size=10)
  378. data = ["1. I have no chance to go sightseeing this summer. (chance)",
  379. "2. And with that, we conclude the third and final example. (third)",
  380. "3. He lives a healthy and normal life and has a strong body. (healthy)",
  381. "4. Popular music evolved from folk songs (song)",
  382. "5. The town is famous for its name. (for)",
  383. "6. Let's call room service, I need a bottle of wine. (wine)",
  384. "7. That was the beginning of my life's work. (life)",
  385. "8. The student wants to learn something. (learn)",
  386. "9. How long did the movie last? (last)",
  387. "10. I don't want to marry while I am studying. (marry)",
  388. "11. Each paragraph begins on a new line. (paragraph)",
  389. "12. Mike studies harder, so his grades are getting better and better. (better)",
  390. "13. Tutors are better and more helpful than school teachers in any fields a student respondent said. (helpful)",
  391. "14. Our team won a great victory and won the prize. (prize)",
  392. "15. His performance at the concert last night proved that he is in the top of international pianists. (concert)"]
  393. for i in example_sentence:
  394. p = docx.add_blank_paragraph(dq=4, dh=4)
  395. p.add_run_to_p("□ ", size=12, font_name="宋体")
  396. p.add_run_to_p(i + "___________")
  397. docx.add_page_section()
  398. @time_use
  399. def section_7(docx: Word, json_data, *args, **kwargs):
  400. def wanxing(index, article_single):
  401. article_id = article_single['Id']
  402. article_length = article_single['AllWordAmount']
  403. strange_words_ids = [i['MeanId'] for i in json_data['StrangeWords']]
  404. explanatory_words_ids = [i['MeaningId'] for i in article_single['ExplanatoryWords']]
  405. select_text = []
  406. for ques_index, candidates in enumerate(article_single['Questions'], start=1):
  407. single_select_text = ''
  408. for s in candidates['Candidates']:
  409. single_select_text += s['Label'] + '. '
  410. participle = s['Participle']
  411. if participle:
  412. single_select_text += participle + ' \n'
  413. else:
  414. text = s['Text']
  415. single_select_text += text + ' \n'
  416. select_text.append(f"{ques_index}. {single_select_text}")
  417. all_select_text = "\n".join(select_text)
  418. article_main: str = article_single['English'] + "\n\n郑重提示:认真看完全文再看问题。\n\n" + all_select_text
  419. article_main_list = article_main.split(" ")
  420. explanatory_words = "\n\n".join(
  421. [f"{index}. {i['Spell']} {i['SymbolsEn']} {i['SymbolsAm']} {i['Meaning']}" for index, i in
  422. enumerate(article_single['ExplanatoryWords'], start=1)])
  423. sub_title_maker(docx, "真题强化练", "智能匹配难度,轻松提升阅读")
  424. tb = Table(docx, 1, 1, tb_name="真题强化练", border=True)
  425. tb.set_tb_colum_width(0, 460)
  426. text = ["练习中不认识的单词,尽量猜测词义,并用红笔加以标记。\n",
  427. "答题完毕后,可查字典,并注释在右侧批注区,不要在原文上注释。复习时不必通读全文,结合上下文能回忆起标记词的词义即可,想不起的再对照批注区。\n",
  428. "完形填空是优秀的测验题型,却不适合用于训练阅读能力和提升词汇量,所以建议在阅读能力(理解度、速度、难度)达标后再做完形填空题型练习。\n",
  429. "阅读能力达标的同学,按三遍法做完形填空,基本可以达到满分。三遍法要求如下:\n",
  430. "第一遍(理解):结合选项通读全文,以求理解文章主旨,但不动笔,以免形成成见。\n",
  431. "第二遍(填空):通读全文,从候选词中选出适宜项目,将完整的单词填入空格,使文章连贯。\n",
  432. "第三遍(核验):通读填空后的全文,确认上下文无矛盾之处。\n",
  433. "三遍通读均应记录起讫时间,并将速度纳入能力考核项目。能力合格者,考试中也应有充裕时间完成以上 3 遍通读。\n",
  434. "阅读计时从此处开始,请按顺序完成阅读,并注意记录时间。\n",
  435. "\n"]
  436. text2 = [f"全题长度(含问题及选项):{article_length}; 编号:{article_id};\n",
  437. "第一遍(理解)开始时间:_________________ 第二遍(填空)开始时间:_________________\n",
  438. "第三遍(核验)开始时间:_________________"]
  439. cell_p = tb.get_cell_paragraph(0, 0, align="left", dq=10, dh=10)
  440. p = ParagraphBase(cell_p)
  441. for t in text:
  442. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  443. p.add_run_to_p(t, size=10)
  444. for t2 in text2:
  445. p.add_run_to_p(t2, size=10)
  446. docx.add_blank_paragraph()
  447. tb1 = Table(docx, 1, 3)
  448. tb1.set_tb_colum_width(width=[90, 370, 5])
  449. tb1_p = ParagraphBase(tb1.get_cell_paragraph(0, 0, align="left"))
  450. tb1_p.add_pic("make_docx_demo/static/lianxi1.jpg", width=2.5)
  451. tb1.set_cell_text(0, 1, f"本篇编号:{article_id},篇幅(含问题选项):{article_length} 词 阅读开始时间: 点 分 秒",
  452. size=9.5, underline=True, border=False, align="left")
  453. tb2 = Table(docx, rows=1, cols=2, border=True, tb_name="完形填空")
  454. tb2.set_tb_colum_width(width=[320, 140])
  455. tb2_p = ParagraphBase(tb2.get_cell_paragraph(0, 0, align="left"))
  456. for w in article_main_list:
  457. word = re.search(r"\[(\d+)]", w)
  458. if word:
  459. w = w[:w.find('[')]
  460. meaning_id = int(word.group(1))
  461. if meaning_id in strange_words_ids:
  462. tb2_p.add_run_to_p(w + ' ', size=10.5, bold=True)
  463. elif meaning_id in explanatory_words_ids:
  464. tb2_p.add_run_to_p(w + ' ', size=10.5, italic=True)
  465. else:
  466. tb2_p.add_run_to_p(w + ' ', size=10.5)
  467. else:
  468. tb2_p.add_run_to_p(w + ' ', size=10.5)
  469. tb2.set_cell_text(0, 1, explanatory_words, size=10.5, font_color=(80, 80, 80), align="left")
  470. docx.add_blank_paragraph()
  471. tail_zhushi = """第一遍(理解)结束时间:__________用时:____秒
  472. 第二遍(填空)结束时间:__________用时:____秒
  473. 第三遍(核验)结束时间:__________用时:____秒
  474. 总计用时:____分____秒
  475. 阅读计时在此结束。
  476. 今日总计阅读量 392 词,用时____秒,整份学案共有____个题目答对。答题用时、答对题数两项数据请抄写到筛查反馈表页脚。"""
  477. docx.add_paragraph(tail_zhushi, size=10.5)
  478. docx.add_blank_paragraph()
  479. def reading(index, article_single):
  480. all_article_length = 0
  481. def single_yuedu(index, a):
  482. article_id = a['Id']
  483. article_length = a['AllWordAmount']
  484. nonlocal all_article_length
  485. all_article_length += article_length
  486. strange_words_ids = [i['MeanId'] for i in json_data['StrangeWords']]
  487. explanatory_words_ids = [i['MeaningId'] for i in a['ExplanatoryWords']]
  488. select_text = []
  489. for ques_index, candidates in enumerate(a['Questions'], start=1):
  490. single_select_text = ''
  491. subject = candidates['Subject'] + '\n'
  492. for s in candidates['Candidates']:
  493. single_select_text += s['Label'] + '. '
  494. participle = s['Participle']
  495. if participle:
  496. single_select_text += participle + ' \n'
  497. else:
  498. text = s['Text']
  499. single_select_text += text + ' \n'
  500. select_text.append(str(ques_index) + ". " + subject + single_select_text)
  501. all_select_text = "\n".join(select_text)
  502. article_main: str = a['English'] + "\n\n郑重提示:认真看完全文再看问题。\n\n" + all_select_text
  503. article_main_list = article_main.split(" ")
  504. explanatory_words = "\n\n".join(
  505. [f"{index}. {i['Spell']} {i['SymbolsEn']} {i['SymbolsAm']} {i['Meaning']}" for index, i in
  506. enumerate(a['ExplanatoryWords'], start=1)])
  507. tb1 = Table(docx, 1, 3, tb_name="图片小标题")
  508. tb1.set_tb_colum_width(width=[90, 370, 5])
  509. tb1_p = ParagraphBase(tb1.get_cell_paragraph(0, 0, align="left"))
  510. tb1_p.add_pic(f"make_docx_demo/static/lianxi{index}.jpg", width=2.5)
  511. tb1.set_cell_text(0, 1, f"本篇编号:{article_id},篇幅(含问题选项):{article_length} 词 阅读开始时间: 点 分 秒",
  512. size=9.5, underline=True, border=False, align="left")
  513. tb2 = Table(docx, rows=1, cols=2, border=True, tb_name="七选五")
  514. tb2.set_tb_colum_width(width=[320, 140])
  515. tb2_p = ParagraphBase(tb2.get_cell_paragraph(0, 0, align="left"))
  516. for w in article_main_list:
  517. word = re.search(r"\[(\d+)]", w)
  518. if word:
  519. w = w[:w.find('[')]
  520. meaning_id = int(word.group(1))
  521. if meaning_id in strange_words_ids:
  522. tb2_p.add_run_to_p(w + ' ', size=10.5, bold=True)
  523. elif meaning_id in explanatory_words_ids:
  524. tb2_p.add_run_to_p(w + ' ', size=10.5, italic=True)
  525. else:
  526. tb2_p.add_run_to_p(w + ' ', size=10.5)
  527. else:
  528. tb2_p.add_run_to_p(w + ' ', size=10.5)
  529. tb2.set_cell_text(0, 1, explanatory_words, size=10.5, font_color=(80, 80, 80), align="left", centre=False)
  530. docx.add_blank_paragraph()
  531. tail_zhushi = """完成时间:_____点_____分_____秒,本篇用时:_____秒。"""
  532. docx.add_paragraph(tail_zhushi, size=10.5)
  533. docx.add_blank_paragraph()
  534. "---------------------开始单篇运行---------------------"
  535. if index == 1:
  536. sub_title_maker(docx, "阅读提升练", "智能匹配难度,轻松提升阅读", "春笋智学, 高效学习专家")
  537. tb = Table(docx, 1, 1, tb_name="真题强化练", border=True)
  538. tb.set_tb_colum_width(0, 460)
  539. text = ["阅读中不认识的单词,尽量猜测词义,并用红笔加以标记,以便日后快速回顾。\n",
  540. "读完全文后,可查字典,并抄在右侧批注区,不要在原文上注释。复习时不必通读全文,结合上下文能回忆起标记词的词义即可,想不起的再对照批注区。\n",
  541. "阅读训练的目的是提高对英语词、句、篇的敏感度,答题只是检验学习成果的手段,所以切勿为了快速做题而跳读、略读。阅读速度是很重要的训练指标,请在确实理解词句的基础上尽量提高阅读速度。只要平时扎实阅读,考试中不会没有时间认真读题。\n",
  542. "阅读计时从此处开始,请按顺序完成阅读,并注意记录时间。\n",
  543. ]
  544. cell_p = tb.get_cell_paragraph(0, 0, align="left", dq=10, dh=10)
  545. p = ParagraphBase(cell_p)
  546. for t in text:
  547. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  548. p.add_run_to_p(t, size=10)
  549. docx.add_blank_paragraph()
  550. single_yuedu(index, article_single)
  551. tail_zhushi = f"""阅读计时在此结束。
  552. 今日总计阅读量 {all_article_length} 词,用时________秒,整份学案共有_______个题目答对。
  553. 答题用时、答对题数两项数据请抄写到筛查反馈表页脚。
  554. 请翻译并熟读下列句子。熟读时停顿要合理,并做到大声、清晰、流畅、快速;口音可逐步调整,不必立刻追求十分标准。"""
  555. docx.add_paragraph(tail_zhushi, size=10.5)
  556. docx.add_blank_paragraph()
  557. def seven_to_five(index, article_single):
  558. article_id = article_single['Id']
  559. article_length = article_single['AllWordAmount']
  560. strange_words_ids = [i['MeanId'] for i in json_data['StrangeWords']]
  561. explanatory_words_ids = [i['MeaningId'] for i in article_single['ExplanatoryWords']]
  562. select_text = []
  563. for ques_index, s_candidates in enumerate(article_single['Candidates'], start=1):
  564. single_select_text = ''
  565. single_select_text += s_candidates['Label'] + '. '
  566. participle = s_candidates['Participle']
  567. if participle:
  568. single_select_text += participle
  569. else:
  570. text = s_candidates['Text']
  571. single_select_text += text
  572. select_text.append(f"{single_select_text}")
  573. all_select_text = "\n".join(select_text)
  574. article_main: str = article_single['English'] + "\n\n郑重提示:认真看完全文再看问题。\n\n" + all_select_text
  575. article_main_list = article_main.split(" ")
  576. explanatory_words = "\n\n".join(
  577. [f"{index}. {i['Spell']} {i['SymbolsEn']} {i['SymbolsAm']} {i['Meaning']}" for index, i in
  578. enumerate(article_single['ExplanatoryWords'], start=1)])
  579. sub_title_maker(docx, "阅读提升练", "智能匹配难度,轻松提升阅读", "春笋智学, 高效学习专家")
  580. tb = Table(docx, 1, 1, tb_name="真题强化练", border=True)
  581. tb.set_tb_colum_width(0, 460)
  582. text = ["阅读中不认识的单词,尽量猜测词义,并用红笔加以标记。\n",
  583. "读完全文后,可查字典,并抄在右侧批注区,不要在原文上注释。复习时不必通读全文,结合上下文能回忆起标记词的词义即可,想不起的再对照批注区。\n",
  584. "7 选 5 题型是测试学生对文章理解程度的好题型,但因打破里文章的连贯性,故不是训练阅读能力的好素材。建议学生在阅读基本能力(理解度、速度、难度)达标后再开展 7 选 5 题型训练。若不能胜任本练习,请回到词汇与阅读训练,先打好基础。\n",
  585. "阅读计时从此处开始,请按顺序完成阅读,并注意记录时间。\n",
  586. ]
  587. cell_p = tb.get_cell_paragraph(0, 0, align="left", dq=10, dh=10)
  588. p = ParagraphBase(cell_p)
  589. for t in text:
  590. p.add_run_to_p("☆ ", size=10, font_name="MS Gothic")
  591. p.add_run_to_p(t, size=10)
  592. docx.add_blank_paragraph()
  593. tb1 = Table(docx, 1, 3, tb_name="图片小标题")
  594. tb1.set_tb_colum_width(width=[90, 370, 5])
  595. tb1_p = ParagraphBase(tb1.get_cell_paragraph(0, 0, align="left"))
  596. tb1_p.add_pic("make_docx_demo/static/lianxi1.jpg", width=2.5)
  597. tb1.set_cell_text(0, 1, f"本篇编号:{article_id},篇幅(含问题选项):{article_length} 词 阅读开始时间: 点 分 秒",
  598. size=9.5, underline=True, border=False, align="left")
  599. tb2 = Table(docx, rows=1, cols=2, border=True, tb_name="七选五")
  600. tb2.set_tb_colum_width(width=[320, 140])
  601. tb2_p = ParagraphBase(tb2.get_cell_paragraph(0, 0, align="left"))
  602. for w in article_main_list:
  603. word = re.search(r"\[(\d+)]", w)
  604. if word:
  605. w = w[:w.find('[')]
  606. meaning_id = int(word.group(1))
  607. if meaning_id in strange_words_ids:
  608. tb2_p.add_run_to_p(w + ' ', size=10.5, bold=True)
  609. elif meaning_id in explanatory_words_ids:
  610. tb2_p.add_run_to_p(w + ' ', size=10.5, italic=True)
  611. else:
  612. tb2_p.add_run_to_p(w + ' ', size=10.5)
  613. else:
  614. tb2_p.add_run_to_p(w + ' ', size=10.5)
  615. tb2.set_cell_text(0, 1, explanatory_words, size=10.5, font_color=(80, 80, 80), align="left")
  616. docx.add_blank_paragraph()
  617. tail_zhushi = """完成时间:_____点_____分_____秒,用时:_____秒
  618. 阅读计时在此结束。
  619. 今日总计阅读量 292 词,用时________秒,整份学案共有_______个题目答对。
  620. 答题用时、答对题数两项数据请抄写到筛查反馈表页脚。"""
  621. docx.add_paragraph(tail_zhushi, size=10.5)
  622. docx.add_blank_paragraph()
  623. "判断题型;根据题型选择----------------------------"
  624. for index, article_single in enumerate(json_data['Articles'], start=1):
  625. article_type = article_single['Category']
  626. article_type_select = {1: reading, 2: wanxing, 3: seven_to_five}
  627. assert article_type in article_type_select
  628. article_type_select[article_type](index, article_single)
  629. docx.add_page_section()
  630. @time_use
  631. def section_8(docx: Word, json_data, *args, **kwargs):
  632. sub_title_maker(docx, "单词趣味填", "趣味练习,多维提升和巩固")
  633. docx.add_pic_single_paragraph("make_docx_demo/static/happy_word.jpg", align="center", width=14.58)
  634. docx.add_page_section()
  635. @time_use
  636. def section_9(docx: Word, json_data, *args, **kwargs):
  637. def wanxing(index, article_single):
  638. chinese_article = article_single['Chinese']
  639. all_analysis = ''
  640. docx.add_paragraph("答案和解析", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  641. text = "做阅读题的目的是锻炼理解英语文本的能力,答题只是检验理解程度的手段。请尽量根据所给题眼理解解题依据。若需要看汉语解析才能明白,你需要回到词汇与阅读训练,并从较低难度入手,以便打好基础。"
  642. docx.add_paragraph(text, size=9)
  643. for ques_index, question_item in enumerate(article_single['Questions'], start=1):
  644. analysis = question_item['Analysis'].strip()
  645. abcd_label = ''
  646. candidates = question_item['Candidates']
  647. for abcd_selected in candidates:
  648. if abcd_selected['IsRight']:
  649. abcd_label += abcd_selected['Label'].strip()
  650. all_analysis += f"{ques_index}.\n{abcd_label} {analysis}\n"
  651. docx.add_paragraph(all_analysis, size=9)
  652. docx.add_paragraph("全文参考译文", chinese_font_name="微软雅黑", dq=15, dh=5, bold=True)
  653. docx.add_paragraph(chinese_article, size=9, dq=5, dh=5, line_spacing=300)
  654. def reading(index, article_single):
  655. all_analysis = ''
  656. all_difficult_sentences = []
  657. chinese_article = article_single['Chinese']
  658. for ques_index, question_item in enumerate(article_single['Questions'], start=1):
  659. analysis = question_item['Analysis'].strip("\n")
  660. abcd_label = ''
  661. candidates = question_item['Candidates']
  662. for abcd_selected in candidates:
  663. if abcd_selected['IsRight']:
  664. abcd_label += abcd_selected['Label'].strip("\n")
  665. all_analysis += f"{ques_index}.{abcd_label} {analysis}\n"
  666. all_analysis += '\n'
  667. for difficult_sentence_item in article_single['DifficultSentences']:
  668. all_difficult_sentences.append(difficult_sentence_item['Chinese'])
  669. docx.add_paragraph("答案和解析", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  670. text = "做阅读题的目的是锻炼理解英语文本的能力,答题只是检验理解程度的手段。请尽量根据所给题眼理解解题依据。若需要看汉语解析才能明白,你可能需要暂时调低阅读难度。"
  671. docx.add_paragraph(text, size=9)
  672. docx.add_paragraph(all_analysis, size=9)
  673. docx.add_paragraph("难句翻译参考译文", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  674. for index_, difficult_sentence in enumerate(all_difficult_sentences, start=1):
  675. docx.add_paragraph(f'{index_}. {difficult_sentence}', size=9)
  676. docx.add_paragraph("全文参考译文", chinese_font_name="微软雅黑", dq=15, dh=5, bold=True)
  677. docx.add_paragraph(f"Passage {index}", chinese_font_name="微软雅黑", dq=15, dh=5, bold=True)
  678. docx.add_paragraph(chinese_article, size=9)
  679. def seven_to_five(index, article_single):
  680. chinese_article = article_single['Chinese']
  681. all_analysis = ''
  682. docx.add_paragraph("答案和解析", chinese_font_name="微软雅黑", dq=5, dh=5, bold=True)
  683. text = "做阅读题的目的是锻炼理解英语文本的能力,答题只是检验理解程度的手段。请尽量根据所给题眼理解解题依据。若需要看汉语解析才能明白,你需要回到词汇与阅读训练,并从较低难度入手,以便打好基础。"
  684. docx.add_paragraph(text, size=9)
  685. for q_index, question_item in enumerate(article_single['Questions'], start=1):
  686. analysis = question_item['Analysis']
  687. abcd_label = ''
  688. candidates = question_item['Candidates']
  689. for abcd_selected in candidates:
  690. if abcd_selected['IsRight']:
  691. abcd_label += abcd_selected['Label']
  692. all_analysis += f"{q_index}.{abcd_label} {analysis}\n"
  693. docx.add_paragraph(all_analysis, size=9)
  694. docx.add_paragraph("全文参考译文", chinese_font_name="微软雅黑", dq=15, dh=5, bold=True)
  695. docx.add_paragraph("Passage 1", chinese_font_name="微软雅黑", dq=15, dh=5, bold=True)
  696. docx.add_paragraph(chinese_article, size=9, dq=5, dh=5, line_spacing=300)
  697. "判断题型;根据题型选择----------------------------"
  698. sub_title_maker(docx, "解题自主纠", "自主学习,逐步养成良好学习习惯")
  699. for index, article_single in enumerate(json_data['Articles'], start=1):
  700. article_type = article_single['Category']
  701. article_type_select = {1: reading, 2: wanxing, 3: seven_to_five}
  702. assert article_type in article_type_select
  703. article_type_select[article_type](index, article_single)
  704. docx.add_blank_paragraph()
  705. docx.add_docx_component("make_docx_demo/word_component/blank.docx")
  706. docx.add_page_section()
  707. @time_use
  708. def section_10(docx: Word, json_data, scanpage_format, **kwargs):
  709. docx.add_paragraph("☆ 请写出词义,再对照筛査表批改。词义顺序可互换;答案意思相符即可,不要求一字不差。批改结果眷抄到筛査表。", size=9, dq=2,
  710. dh=2)
  711. tb = Table(docx, 50, 4, tb_name="写出词义")
  712. tb.set_tb_colum_width(width=[110, 120, 110, 120])
  713. for row in range(50):
  714. tb.set_cell_text(row, 0, str(row + 1) + " " + "rich", size=8.5, dq=1, dh=1, border=False)
  715. tb.set_cell_text(row, 1, "□________________", size=10, dq=0, dh=0, border=False)
  716. tb.set_cell_text(row, 2, str(row + 51) + " " + "rich", size=8.5, dq=1, dh=1, border=False)
  717. tb.set_cell_text(row, 3, "□________________", size=10, dq=0, dh=0, border=False)
  718. tb.set_row_height(13)
  719. docx.add_page_break()
  720. docx.add_paragraph("☆ 请在需要加强学习的词义前方框中划线,两头各超出 1 毫米为宜(示例:□☑52.example);请保持本表整洁并交回。", size=9, dq=2,
  721. dh=2)
  722. tb2 = Table(docx, 25, 8, tb_name="划线表")
  723. tb2.set_tb_colum_width(width=[57.5] * 8)
  724. docx.add_blank_paragraph(dq=5, dh=5)
  725. for row in range(25):
  726. tb2.set_cell_text(row, 0, "[01] Tuesday", size=8.5, border=False, dq=1.2, dh=1.2)
  727. tb2.set_cell_text(row, 1, "星期二", size=8.5, border="right", dq=1.2, dh=1.2)
  728. tb2.set_cell_text(row, 2, "[01] Tuesday", size=8.5, border=False, dq=1.2, dh=1.2)
  729. tb2.set_cell_text(row, 3, "星期二", size=8.5, border="right", dq=1.2, dh=1.2)
  730. tb2.set_cell_text(row, 4, "[01] Tuesday", size=8.5, border=False, dq=1.2, dh=1.2)
  731. tb2.set_cell_text(row, 5, "星期二", size=8.5, border="right", dq=1.2, dh=1.2)
  732. tb2.set_cell_text(row, 6, "[01] Tuesday", size=8.5, border=False, dq=1.2, dh=1.2)
  733. tb2.set_cell_text(row, 7, "星期二", size=8.5, border=False, dq=1.2, dh=1.2)
  734. docx.set_page_column(5)
  735. docx.add_docx_component("make_docx_demo/word_component/component.docx")
  736. docx.end_page_column()
  737. if scanpage_format == 3:
  738. docx.add_page_section()
  739. def two_check_page(docx: Word, json_data, **kwargs):
  740. def empty_filter_page(class_name, student_name, page_title, page_sub_title, t_datetime, word_data_list):
  741. if len(word_data_list) % 2 != 0:
  742. word_data_list.append("")
  743. tb = Table(docx, 1, 3, tb_name="头部三元素")
  744. tb.set_tb_colum_width(width=[40, 100, 100])
  745. p_cell = tb.get_cell_paragraph(0, 0, dq=10)
  746. p = ParagraphBase(p_cell)
  747. p.add_pic("make_docx_demo/static/logo2.png", width=Inches(1.2))
  748. tb.set_cell_text(0, 1, f"{class_name}\n{student_name}", border=False, size=8, dh=2)
  749. tb.set_cell_text(0, 2, f"{page_title}\n{page_sub_title}", border=False, size=8, dh=2)
  750. docx.add_paragraph("请写出词义,再对照筛查表批改。词义顺序可互换;答案意思相符即可,不要求一字不差。批改结果誊抄到筛查表。", size=9)
  751. tb = Table(docx, rows=0, cols=4, tb_name="第一页筛查表")
  752. tb.set_all_border_fastly(xml=True, outside_side_border=True, outside_side_border_size=5)
  753. half_count = int(len(word_data_list) / 2)
  754. for index, row in enumerate(range(half_count)):
  755. first_word, second_word = word_data_list[row], word_data_list[row + half_count]
  756. cell3 = f"{index + 1 + half_count}. {second_word}" if second_word else ""
  757. cell4 = "□ ___________________________" if second_word else ""
  758. data = [f"{index + 1}. {first_word}", "□ ___________________________", cell3, cell4]
  759. tb.add_table_row_data_xml_fastly(data, font_size=[10.5, 9, 10.5, 9])
  760. tb.set_row_height(13.8)
  761. tb.set_table_width_xml([2124, 3257, 2140, 3257])
  762. blank_count = " " * 80
  763. p = docx.add_blank_paragraph(dq=5)
  764. p.add_run_to_p(f"{t_datetime} {page_title}-{page_sub_title}{blank_count}", size=8, chinese_font_name="仿宋", font_name="仿宋")
  765. docx.add_page_break()
  766. def filter_table_page(page_id, class_name, student_name, page_title, page_sub_title, t_datetime,
  767. foot_description, foot_description2, article_type, word_data_list2):
  768. if len(word_data_list2) % 2 != 0:
  769. word_data_list2.append(["", ""])
  770. tb = Table(docx, 1, 5, tb_name="头部五元素")
  771. tb.set_tb_colum_width(width=[40, 130, 130, 150, 70])
  772. p_cell = tb.get_cell_paragraph(0, 0, dq=10)
  773. p = ParagraphBase(p_cell)
  774. p.add_pic("make_docx_demo/static/logo2.png", width=Inches(1.2))
  775. tb.set_cell_text(0, 1, f"{class_name}\n{student_name}", border=False, size=8)
  776. tb.set_cell_text(0, 2, f"{page_id}", border=False, size=16, dh=2, bold=True, font_name="黑体")
  777. tb.set_cell_text(0, 3, f"{page_title}\n{page_sub_title}", border=False, size=8)
  778. p_cell = tb.get_cell_paragraph(0, 4)
  779. p = ParagraphBase(p_cell)
  780. p.add_pic(qrcode_maker(f"{page_id}"), width=Inches(0.5))
  781. pp = docx.add_blank_paragraph()
  782. p_base = ParagraphBase(pp)
  783. p_base.p.add_run_to_p("请在需要加强学习的词义前方框中划线,两头各超出1毫米为宜(示例:", size=9)
  784. p_base.p.add_pic("make_docx_demo/static/line_example.png", width=Inches(0.8))
  785. p_base.p.add_run_to_p(" );请保持本表整洁并交回。", size=9)
  786. tb = Table(docx, rows=0, cols=4, tb_name="第二页筛查表")
  787. ## 1234横着放
  788. #
  789. #
  790. ## 1234竖着放
  791. total_row = int(len(word_data_list2) / 2)
  792. for row in range(total_row):
  793. spell1, meaning1 = word_data_list2[row]
  794. spell2, meaning2 = word_data_list2[total_row + row]
  795. cell3 = f"{total_row + row + 1}. {spell2}" if spell2 else ""
  796. cell4 = f"□ {meaning2}" if meaning2 else ""
  797. data = [f"{row + 1}. {spell1}", f"□ {meaning1}", cell3, cell4]
  798. tb.add_table_row_data_xml_fastly(data, font_size=[10.5, 9, 10.5, 9])
  799. tb.set_all_border_fastly(xml=True, outside_side_border=True, outside_side_border_size=5)
  800. tb.set_row_height(13.6)
  801. tb.set_table_width_xml([2124, 3257, 2140, 3257])
  802. if article_type == 1:
  803. docx.add_paragraph(f"{t_datetime} {page_title}-{page_sub_title}{foot_description}", size=8, chinese_font_name="仿宋",
  804. font_name="仿宋", dq=5)
  805. docx.add_paragraph(foot_description2, align="right", size=8, chinese_font_name="仿宋")
  806. else:
  807. docx.add_paragraph(f"{t_datetime} {page_title}-{page_sub_title}{foot_description}", size=8, chinese_font_name="仿宋",
  808. font_name="仿宋", dq=5)
  809. student_name = json_data.get("StudentInfo").get("StudentName", '')
  810. class_name = json_data.get("StudentInfo").get("ClassName", '')
  811. t_datetime = time.strftime("%Y-%m-%d %H:%M", time.localtime())
  812. article_type = json_data['Articles'][0]['Category']
  813. is_add_empty_filter_page = json_data['Config']['AddEmptyFilterPage']
  814. """---------------------------------------------------------------------------------"""
  815. for index, page in enumerate(json_data['ScreeningScanPages'], start=1):
  816. page_id = str(page['PageId']).rjust(11, "0")
  817. if index >= 2:
  818. docx.add_page_break()
  819. page_title = page['Title']
  820. page_sub_title = page['SubTitle']
  821. foot_description = page['FootDescription']
  822. foot_description2 = page['FootDescription2']
  823. word_data_list1 = []
  824. word_data_list2 = []
  825. for i in page['FilterTable']['Items']:
  826. word_data_list1.append(i['Spell'])
  827. word_data_list2.append([i['Spell'], i['Meaning']])
  828. if is_add_empty_filter_page:
  829. empty_filter_page(class_name, student_name, page_title, page_sub_title, t_datetime, word_data_list1)
  830. filter_table_page(page_id, class_name, student_name, page_title, page_sub_title, t_datetime,
  831. foot_description, foot_description2, article_type, word_data_list2)
  832. @time_use
  833. def other(docx, json_data, **kwargs):
  834. sections = docx.doc.sections
  835. for section in sections[:-1]:
  836. section.top_margin = Inches(0.3)
  837. section.bottom_margin = Inches(0.3)
  838. section.left_margin = Inches(0.8)
  839. section.right_margin = Inches(0.8)
  840. sections[-1].top_margin = Inches(0.1)
  841. sections[-1].bottom_margin = Inches(0.1)
  842. sections[-1].left_margin = Inches(0.5)
  843. sections[-1].right_margin = Inches(0.5)
  844. header_maker(docx, json_data)
  845. def start_make_word(json_data, document_format, scanpage_format):
  846. try:
  847. docx = Word(save_file_name="develop.docx", start_template_name="make_docx_demo/word_component/start_template.docx")
  848. menu = [section_1, section_2, section_3, section_4, section_4_1,
  849. section_5, section_6, section_7, section_8, section_9, ]
  850. if scanpage_format == 1:
  851. menu.append(two_check_page)
  852. elif scanpage_format == 2:
  853. menu.append(section_10)
  854. elif scanpage_format == 3:
  855. menu.append(section_10)
  856. menu.append(two_check_page)
  857. menu.append(other)
  858. for s in menu:
  859. s(docx=docx, json_data=json_data, scanpage_format=scanpage_format)
  860. docx.save_docx()
  861. if document_format == 1:
  862. return "develop.docx"
  863. else:
  864. convert_word_to_pdf("develop")
  865. return "develop.pdf"
  866. except Exception as e:
  867. log_err_e(e)
  868. if __name__ == '__main__':
  869. import os
  870. t = time.time()
  871. os.chdir("..")
  872. start_make_word(test_json5, 1, 1)
  873. print(time.time() - t)