main.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:NYCSL2 作者: HMProgrammingClub 项目源码 文件源码
def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument("problemID", type=str, required=True, location="json")
        parser.add_argument("userID", type=str, required=True, location="json")
        parser.add_argument("file", type=FileStorage, required=True, location="files")
        entry = parser.parse_args()

        try:
            if db.problem.find_one({"_id": ObjectId(entry['problemID'])}) == None:
                abort(400)
            if db.user.find_one({"_id": entry['userID']}) == None:
                abort(400)
        except:
            abort(400)

        problemName =  db.problem.find_one({"_id": ObjectId(entry['problemID'])})['name']
        gradingFilePath = os.path.join(os.path.join(PROBLEMS_DIR, problemName.lower()), GRADING_SCRIPT)
        command = "python3 "+gradingFilePath+" \""+entry["file"].stream+"\""
        gradingOutput = subprocess.Popen(shlex.split(command.replace('\\','/')), stdout=subprocess.PIPE).communicate()[0]
        structuredGradingOutput = json.loads(gradingOutput)

        status_code = None
        if "score" in structuredGradingOutput:
            entry["score"] = structuredGradingOutput["score"]
            entry.pop("file")
            db.entry.insert_one(entry)
            status_code = 201
        else:
            status_code = 400

        return jsonify(structuredGradingOutput, status=status_code)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号