Commit 1aaf3d08 authored by 张鹏程's avatar 张鹏程

1. 增加文件上传功能

parent b342e0ad
......@@ -7,5 +7,9 @@ FEATURE_HOST_MY = 'http://localhost:23010'
url_reportanalysis = '/report'
url_uploadfiles= '/uploadfiles'
TO_JSON = FILE_PATH+'/to_json'
HTML_PATH = FILE_PATH+'/html'
......@@ -74,7 +74,6 @@ class ReportAnalysis(BaseHandler):
))
self.flush()
# import json
# outpath = r'/Users/zhangpengcheng/Documents/量化派代码管理/credit_report/html/provinces.json'
# with open(outpath,"w+",encoding="utf-8") as f:
......
# -*- coding:utf-8 -*-
from utils import JsonUtil
from handler.Base_Handler import BaseHandler
from config import settings
class UpLoadFiles(BaseHandler):
def post(self):
self._filepath = self.get_argument('filepath', default=None)
if self._filepath == None or self._filepath == '':
self.write(JsonUtil.build_json(code = JsonUtil.Constants.Code_Params_Error,
mssage=JsonUtil.Constants.Msg_Params_Error.format('filepath',self._filepath)))
self.flush()
else:
filepath = self._filepath
isFile = False
try :
with open(filepath, 'rb') as f:
with open(settings.HTML_PATH+'/'+self._filepath.split('/')[-1],'wb+') as f_to:
f_to.write(f.read())
f_to.close()
self.write(JsonUtil.build_json(code=JsonUtil.Constants.Code_Success,
mssage=JsonUtil.Constants.Msg_Success,
report='文件上传成功'
))
f.close()
self.flush()
self.finish()
except IOError as e:
self.write(JsonUtil.build_json(code = JsonUtil.Constants.Code_FileUp_Error,
mssage = JsonUtil.Constants.Msg_FileUp_Error))
self.flush()
......@@ -7,4 +7,5 @@ SQLAlchemy==1.2.5
jupyter
paramiko
cpca
lxml==3.8.0
\ No newline at end of file
lxml==3.8.0
bs4
\ No newline at end of file
......@@ -14,9 +14,10 @@ from config import settings as URL
# from handler import LoanDueRateHandler
from tornado.options import define, options
from handler import ReportAnalysis_Handler
from handler import ReportAnalysis_Handler,UpLoadFiles_Handler
from tornado.options import define, options
define("port", default=20010, help="run on the given port ", type=int)
define("log_path", default='/tmp', help="log path ", type=str)
......@@ -31,6 +32,7 @@ class LogFormatter(tornado.log.LogFormatter):
def apps():
return Application([
(URL.url_reportanalysis, ReportAnalysis_Handler.ReportAnalysis),
(URL.url_uploadfiles, UpLoadFiles_Handler.UpLoadFiles),
])
......@@ -51,4 +53,4 @@ if __name__ == "__main__":
# http_server = tornado.httpserver.HTTPServer(app)
# http_server.bind(options.port)
# http_server.start()
# tornado.ioloop.IOLoop.instance().start()
# tornado.ioloop.IOLoop.instance().start()
\ No newline at end of file
......@@ -21,7 +21,6 @@ class Constants:
Code_LoginToken_Auth_Error = -2
Msg_LoginToken_Auth_Error = 'token登陆认证错误'
Code_Error = -3
Msg_Error = '数据异常'
......@@ -31,7 +30,10 @@ class Constants:
Code_File_Error = -5
Msg_File_Error = '文件读取错误'
Code_Analysis_Error = -6
Code_FileUp_Error = -6
Msg_FileUp_Error = '文件上传失败'
Code_Analysis_Error = -7
Msg_Analysis_Error = 'html 解析错误'
Code_Error_Value = 506
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment