exportStudentFile.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import time
  2. import hashlib
  3. import requests
  4. import config
  5. import csv
  6. import os
  7. output = config.outputpath + "/" + str(config.examId)
  8. if not os.path.exists(output):
  9. os.makedirs(output)
  10. #savepath = output + "/" + "mediaimport.csv"
  11. savestudentpath=output + "/" + "examstudent.csv"
  12. mediaimportlist=[]
  13. examstudentlist=[]
  14. def main():
  15. queryExamMarkingInfo()
  16. # with open(savepath, 'w', encoding='utf-8', newline='') as f:
  17. # writer = csv.writer(f)
  18. # writer.writerow(['准考证号', '卷型'])
  19. # for row in mediaimportlist:
  20. # print(row)
  21. # writer.writerow(row)
  22. with open(savestudentpath, 'w', encoding='utf-8', newline='') as f:
  23. writer = csv.writer(f)
  24. writer.writerow(["课程代码","课程名称","准考证号","学号","姓名"])
  25. for row in examstudentlist:
  26. print(row)
  27. writer.writerow(row)
  28. def queryExamMarkingInfo():
  29. """
  30. 获取阅卷信息
  31. """
  32. url=config.oedomain+"api/core/oe/admin/examRecordForMarking/findExamRecordForMarkingInfo"
  33. data = {
  34. "examId": config.examId,
  35. "courseId": "",
  36. "batchNum": ""
  37. }
  38. headers=createRpcheader("4","OE")
  39. result = requests.post(
  40. url, headers=headers,
  41. json=data)
  42. if result.status_code==200:
  43. examRecordForMarkingBeanList=result.json()['examRecordForMarkingBeanList']
  44. for examRecordForMarkingBean in examRecordForMarkingBeanList:
  45. queryExamValidRecordData(examRecordForMarkingBean['courseId'],1)
  46. else:
  47. print("查询阅卷信息失败")
  48. def queryExamValidRecordData(courseId,pageNo):
  49. """
  50. 获取全部考生的阅卷信息
  51. """
  52. url=config.oedomain+"api/core/oe/admin/examRecordForMarking/queryValidExamRecordInfoPage"
  53. data = {
  54. "examId": config.examId,
  55. "courseId": courseId,
  56. "start": pageNo,
  57. "size":200
  58. }
  59. headers = createRpcheader("4","OE")
  60. result = requests.post(
  61. url, headers=headers,
  62. json=data)
  63. if result.status_code==200:
  64. examRecordForMarkingBeanList=result.json()['examRecordForMarkingBeanList']
  65. if len(examRecordForMarkingBeanList) > 0:
  66. for examRecordForMarkingBean in examRecordForMarkingBeanList:
  67. # 取试卷题目
  68. course = getCourse(courseId)
  69. examstudent=queryExamStudent(examRecordForMarkingBean["examStudentId"])
  70. print(examstudent)
  71. examstudentlist.append([examstudent["courseCode"],examstudent["courseName"],
  72. examRecordForMarkingBean["examRecordDataId"],examstudent["identityNumber"],examstudent["studentName"]])
  73. #mediaimportlist.append([examRecordForMarkingBean["examRecordDataId"],examRecordForMarkingBean["paperType"]])
  74. #存储到本地
  75. time.sleep(1)
  76. next = result.json()["next"]
  77. queryExamValidRecordData(courseId,next)
  78. else:
  79. print("没有剩余课程")
  80. def queryExamStudent(examstudentid):
  81. url=config.examworkdomain+"api/core/examwork/examStudent/getExamStudent"
  82. headers = createRpcheader("2", "E")
  83. data={
  84. "rootOrgId":config.rootOrgId,
  85. "examStudentId":examstudentid,
  86. }
  87. result = requests.post(
  88. url, headers=headers,
  89. json=data)
  90. if result.status_code==200:
  91. examstudent=result.json()["examStudentBean"]
  92. return examstudent
  93. else:
  94. print(("query examstudent %s failed")%(str(examstudentid)))
  95. def getCourse(courseId):
  96. url=config.basedomain+"api/core/basic/course/getCoursesByIdList"
  97. headers =createRpcheader("1","B")
  98. data={
  99. "courseIdList":[courseId]
  100. }
  101. result = requests.post(
  102. url, headers=headers,json=data)
  103. if result.status_code==200:
  104. return result.json()["courseList"][0]
  105. def createRpcheader(appid,appcode):
  106. secretkey = "123456"
  107. t = time.time()
  108. secretstr = ''.join([appid, appcode, str(int(round(t * 1000))), secretkey])
  109. accssToken = hashlib.sha256(secretstr.encode("utf-8")).hexdigest()
  110. headers = {
  111. "App-Id": appid,
  112. "App-Code": appcode,
  113. "Trace-Id": "1222222",
  114. "Access-Token": accssToken,
  115. "timestamp": str(int(round(t * 1000)))
  116. }
  117. return headers
  118. if __name__=="__main__":
  119. main()