Skip to content

Commit

Permalink
delete unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
Coaixy committed Dec 20, 2024
1 parent c78e87a commit 7bb2a9e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
51 changes: 26 additions & 25 deletions QuestionBank/QuestionBank.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import difflib
from json import JSONDecodeError

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()
# import uvicorn
# from fastapi import FastAPI
# from fastapi.middleware.cors import CORSMiddleware

app.add_middleware(
CORSMiddleware,
allow_origins=['*'], # 允许的源
allow_credentials=True,
allow_methods=["*"], # 允许的方法,如:GET, POST, OPTIONS 等
allow_headers=["*"], # 允许的头
)
# app = FastAPI()

# app.add_middleware(
# CORSMiddleware,
# allow_origins=['*'], # 允许的源
# allow_credentials=True,
# allow_methods=["*"], # 允许的方法,如:GET, POST, OPTIONS 等
# allow_headers=["*"], # 允许的头
# )


def get_all_json_files_content(directory):
Expand Down Expand Up @@ -134,26 +135,26 @@ def generate_bank(directory='.'):
bank_obj = {}


@app.get("/answer/{question}")
async def get_answer(question: str):
for i in bank_obj:
if question in i:
return {'question': i, 'msg': bank_obj[i]}
closest_match = difflib.get_close_matches(question, bank_obj.keys(), n=1, cutoff=0.6)
if closest_match:
return {'question': closest_match[0], 'msg': bank_obj[closest_match[0]]}
else:
return {'msg': '题目不存在'}
# return {'code': 200, 'msg': bank_obj.get(question, "题目不存在")}
# @app.get("/answer/{question}")
# async def get_answer(question: str):
# for i in bank_obj:
# if question in i:
# return {'question': i, 'msg': bank_obj[i]}
# closest_match = difflib.get_close_matches(question, bank_obj.keys(), n=1, cutoff=0.6)
# if closest_match:
# return {'question': closest_match[0], 'msg': bank_obj[closest_match[0]]}
# else:
# return {'msg': '题目不存在'}
# return {'code': 200, 'msg': bank_obj.get(question, "题目不存在")}


def main():
generate_bank(directory=os.getcwd() + "/QuestionBank")
with open("QuestionBank/result.json", 'r') as f:
global bank_obj
bank_obj = json.load(f)
uvicorn.run(app, host="127.0.0.1", port=8080)
# uvicorn.run(app, host="127.0.0.1", port=8080)


if __name__ == '__main__':
main()
# if __name__ == '__main__':
# main()
3 changes: 0 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# @Author : Coaixy
# @repo : https://www.github.com/coaixy/weiban-tool
import json
import os
import sys
import uuid
import re

import requests


from QuestionBank import QuestionBank
Expand Down

0 comments on commit 7bb2a9e

Please sign in to comment.