| | |
| | | import base64 |
| | | import json |
| | | import logging |
| | | import socketserver |
| | |
| | | import ths_industry_util |
| | | from ocr import ocr_util |
| | | from ocr.ocr_util import OcrUtil |
| | | from third_data import kpl_util |
| | | from trade import bidding_money_manager |
| | | |
| | | |
| | | class OCRServer(BaseHTTPRequestHandler): |
| | |
| | | try: |
| | | data = "" |
| | | try: |
| | | if type(_str) == str: |
| | | data = json.loads(_str) |
| | | except: |
| | | else: |
| | | data = _str |
| | | except Exception as e1: |
| | | raise Exception("json解析失败") |
| | | type = data["type"] |
| | | if type == 100: |
| | | _type = data["type"] |
| | | if _type == 100: |
| | | data = data["data"] |
| | | matId = data["matId"] |
| | | index = data["index"] |
| | |
| | | return_str = json.dumps({"code": 2, "msg": "数据出错"}) |
| | | else: |
| | | return_str = json.dumps({"code": 1, "msg": "数据尚未上传完"}) |
| | | elif type == 101: |
| | | elif _type == 101: |
| | | data = data["data"] |
| | | matId = data["matId"] |
| | | index = data["index"] |
| | |
| | | return_str = json.dumps({"code": 2, "msg": "数据出错"}) |
| | | else: |
| | | return_str = json.dumps({"code": 1, "msg": "数据尚未上传完"}) |
| | | elif _type == 201: |
| | | imgdata = base64.b64decode(data["img"]) |
| | | results = ocr_util.OcrUtil.easy_ocr(imgdata) |
| | | print(results) |
| | | kpl_datas = kpl_util.parse_kpl_datas(results) |
| | | if kpl_datas: |
| | | bidding_money_manager.set_bidding_money(kpl_datas) |
| | | with open("D:/kpl.png", mode="wb") as f: |
| | | f.write(imgdata) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | if str(e).__contains__("json解析失败"): |
| | |
| | | datas = self.rfile.read(int(self.headers['content-length'])) |
| | | _str = str(datas, encoding="gbk") |
| | | # print(_str) |
| | | if _str.find("Content-Disposition: form-data;") > -1: |
| | | start = 0 |
| | | while True: |
| | | start = _str.find("Content-Disposition: form-data;", start + 1) |
| | |
| | | key = _str[name_start:name_end].strip()[6:-1] |
| | | val = _str[name_end:val_end].strip() |
| | | params[key] = val |
| | | else: |
| | | params = json.loads(_str) |
| | | return params |
| | | |
| | | |
| | |
| | | httpd = socketserver.TCPServer((addr, port), handler) |
| | | print("HTTP server is at: http://%s:%d/" % (addr, port)) |
| | | httpd.serve_forever() |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | str_={"id":"123"} |
| | | print(type(str_)==str) |