1 Star 0 Fork 0

吴超/huamei

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
hand_config.py 2.29 KB
一键复制 编辑 原始数据 按行查看 历史
wmc 提交于 2019-10-20 22:27 . first commit
import flask, os,sys,time
from flask import request, send_from_directory
import pandas as pd
from MongoDbHandler import MongoDbHandler
from threading import Thread
server = flask.Flask(__name__)
mongoSession = MongoDbHandler('127.0.0.1', 'admin', 'admin')
def update_kw(path):
# path_dir = 'C:/search_top/'
# file_name=os.listdir(path_dir)[0]
# path=os.path.join(path_dir,file_name)
path_dir, file = os.path.split(path)
df = pd.read_excel(path, header=None)
# print(df)
kw_li = df[0].dropna(axis=0, how='all').tolist()[1:]
pt_li = df[1].dropna(axis=0, how='all').tolist()[1:]
pt2_li = df[2].dropna(axis=0, how='all').tolist()[1:]
# print(pt_li,pt2_li)
site_dict = dict(zip(pt_li, pt2_li))
user = df[3].dropna(axis=0, how='all').tolist()[-1]
email_li = df[4].dropna(axis=0, how='all').tolist()[1:]
history = df[5].dropna(axis=0, how='all').tolist()[-1]
# print(kw_li,site_dict,user,email_li,history)
kw_dict = {}
t = time.time()
ymd = time.strftime('%Y-%m-%d', time.localtime(t))
kw_dict['kw'] = kw_li
kw_dict['sites'] = site_dict
kw_dict['user'] = user
kw_dict['email'] = email_li
kw_dict['history'] = history
kw_dict['time'] = int(t)
kw_dict['年月日'] = ymd
user_dict = {'user': user}
# print(kw_dict)
# A为mongodb的name,B为用户名,C为密码
# result = mongoSession.find_all("jk", "keyword") # D为数据库名,E为集合名
mongoSession.delete_many("jk", "keyword",user_dict)
mongoSession.insert_one("jk", "keyword", kw_dict) # D为数据库名,E为集合名
print('关键词插入成功')
# post方法:上传文件的
@server.route('/upload', methods=['post'])
def upload():
fname = request.files.get('file') #获取上传的文件
if fname and '.xls' in fname.filename:
path_dir=r'C:/search_top/'
file_li=os.listdir(path_dir)
for f in file_li:
os.remove(path_dir+f)
t = time.strftime('%Y%m%d-%H%M%S-')
new_fname = path_dir + t + fname.filename
fname.save(new_fname) #保存文件到指定路径
update_kw(new_fname)
return '{"code": "ok"}'
else:
return '{"msg": "请上传表格文件!"}'
@server.route('/find', methods=['get'])
def find():
return 'ok'
server.run(port=8000, debug=True)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wumuchen/huamei.git
git@gitee.com:wumuchen/huamei.git
wumuchen
huamei
huamei
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385