123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/usr/bin/env/python
- # -*- coding:utf-8 -*-
- import pickle
- from flask import Flask, render_template, send_from_directory
- from flask import request, redirect, Response
- from flask_cors import *
- from multiprocessing import Process, Queue
- import configs
- from structure.structure_main import WordParseStructure
- import os, datetime, hashlib
- import time, json, random
- import pprint
- from utils.ruku_opera_old import Ruku
- logger = configs.myLog(__name__).getlog()
- #
- app = Flask(__name__)
- app.debug = True
- CORS(app, supports_credentials=True) #
- @app.route('/word_structure', methods=["GET", "POST"])
- def word_structure():
- # logger.info("==request.POST.dict==>{}\n".format(request.form.to_dict()))
- mydata = request.json.get("sci_html_data", "")
- is_reparse = request.json.get("is_reparse", "0")
- word_id = request.json.get("paper_id", 0)
- print(mydata)
- # time_str = datetime.datetime.strftime(datetime.datetime.now(), '%Y_%m_%d_%H_%M_%S')
- # new_fpath = os.path.join(file1, str(time_str)+".html")
- # re_f = open(new_fpath, 'w', encoding='utf-8')
- # re_f.write(mydata)
- # try:
- if mydata and word_id:
- res, paper_type = WordParseStructure(mydata, str(word_id), int(is_reparse)).structure()
- pprint.pprint(res)
- return json.dumps(res, ensure_ascii=False)
- # except:
- # # 先保存文件
- # now_time = datetime.datetime.now()
- # time_str = datetime.datetime.strftime(now_time, '%Y_%m_%d_%H_%M_%S')
- # aft_modify = (str(random.random())).encode("utf-8")
- # aft_name = hashlib.md5(aft_modify).hexdigest() + '__' + time_str + '.json'
- #
- # new_fpath = os.path.join(file1, aft_name)
- # re_f = open(new_fpath, 'w', encoding='utf-8')
- # json.dump(mydata, re_f)
- # # return "解析失败"
- # return json.dumps({"items": []}, ensure_ascii=False)
- @app.route('/ruku', methods=["GET","POST"])
- def ruku():
- # is_ruku = request.json.get("is_ruku", 1)
- wordid = request.json.get("paper_id", "")
- items_list = request.json.get("structured_items", "")
- html_data = request.json.get("html_data", "")
- # print(wordid)
- # pickle.dump(items_list, open("F:/zwj/Text_Structure/img_folder/struct_items.pickle", 'wb'))
- # pickle.dump(html_data, open("F:/zwj/Text_Structure/img_folder/html_data.pickle", 'wb'))
- if wordid and items_list:
- res = ruku_upload_img(items_list, html_data, str(wordid))
- print(res)
- return json.dumps(res, ensure_ascii=False)
- @app.route('/ser_static/<path:file_path>', methods=["GET"])
- def ser_static(file_path): # endpoint的位置是函数接口名,不能用static,与flask内部变量重名
- """
- :param file_path: 图片的本地绝对路径
- :return:
- """
- return send_from_directory(configs.IMG_FOLDER, file_path)
- if __name__ == "__main__":
- app.run(host=configs.server_ip, port=configs.server_port, threaded=True, debug=True)
- # 5fc64a0a4994183dda7e74b9
|