Commit eefdd4e8 by dong

fix20230406

parent be5440b7
...@@ -1413,7 +1413,6 @@ def project_graph(): ...@@ -1413,7 +1413,6 @@ def project_graph():
project_source = req_dic['project_source'] # 用于1项目来源区域分布 project_source = req_dic['project_source'] # 用于1项目来源区域分布
industry_name = req_dic['industry_name'] # 用于4项目行业类型分布 industry_name = req_dic['industry_name'] # 用于4项目行业类型分布
data_time = req_dic['data_time'] # ["2022", "01", "12"] data_time = req_dic['data_time'] # ["2022", "01", "12"]
current_year = datetime.now().year current_year = datetime.now().year
now_time3 = '' now_time3 = ''
now_time4 = '' now_time4 = ''
...@@ -1430,7 +1429,6 @@ def project_graph(): ...@@ -1430,7 +1429,6 @@ def project_graph():
if not data_time: if not data_time:
project_obj = ProjectManagement.query.filter( project_obj = ProjectManagement.query.filter(
ProjectManagement.district == district if district else text(''), ProjectManagement.district == district if district else text(''),
# ProjectManagement.sign_time.like('%{}%'.format(str(current_year))),
ProjectManagement.sign_time < now_time1, ProjectManagement.sign_time < now_time1,
ProjectManagement.sign_time >= now_time, ProjectManagement.sign_time >= now_time,
ProjectManagement.is_delete == 0 ProjectManagement.is_delete == 0
...@@ -1438,7 +1436,6 @@ def project_graph(): ...@@ -1438,7 +1436,6 @@ def project_graph():
else: else:
project_obj = ProjectManagement.query.filter( project_obj = ProjectManagement.query.filter(
ProjectManagement.district == district if district else text(''), ProjectManagement.district == district if district else text(''),
# ProjectManagement.sign_time.like('%{}%'.format(str(current_year))),
ProjectManagement.sign_time < now_time4 if now_time4 else text(''), ProjectManagement.sign_time < now_time4 if now_time4 else text(''),
ProjectManagement.sign_time >= now_time3, ProjectManagement.sign_time >= now_time3,
ProjectManagement.is_delete == 0 ProjectManagement.is_delete == 0
...@@ -1542,17 +1539,6 @@ def project_graph(): ...@@ -1542,17 +1539,6 @@ def project_graph():
data = [] data = []
num_li = [] num_li = []
for industry in industry_list: for industry in industry_list:
# if industry == '其他':
# all_project_count = project_obj.count()
# other_num = all_project_count - sum(num_li)
# data_dic = {"name": industry, "value": other_num}
# data.append(data_dic)
# else:
# project_count = project_obj.filter(ProjectManagement.industry == industry).count()
# num_li.append(project_count)
# data_dic = {"name": industry, "value": project_count}
# data.append(data_dic)
# continue
project_count = project_obj.filter(ProjectManagement.industry == industry).count() project_count = project_obj.filter(ProjectManagement.industry == industry).count()
num_li.append(project_count) num_li.append(project_count)
data_dic = {"name": industry, "value": project_count} data_dic = {"name": industry, "value": project_count}
...@@ -1651,9 +1637,6 @@ def project_graph(): ...@@ -1651,9 +1637,6 @@ def project_graph():
return jsonify(code=RET.PARAMERR, msg="参数错误!") return jsonify(code=RET.PARAMERR, msg="参数错误!")
if not data_time: if not data_time:
# now_time = (datetime.now() - relativedelta(years=1)).strftime('%Y-%m-%d')
# now_time = now_time.split('-')
# data_time1 = now_time[0] + '年' + now_time[1] + '月' + now_time[2] + '号-至今'
data_time1 = str(current_year) + '年' data_time1 = str(current_year) + '年'
elif not data_time[2]: elif not data_time[2]:
data_time1 = data_time[0] + '年' + data_time[1] + '月' # ["2022", "01", ""] data_time1 = data_time[0] + '年' + data_time[1] + '月' # ["2022", "01", ""]
...@@ -1681,7 +1664,6 @@ def areal_project(): ...@@ -1681,7 +1664,6 @@ def areal_project():
data_time = req_dic['data_time'] # ["2022", "01", "12"] data_time = req_dic['data_time'] # ["2022", "01", "12"]
current_year = datetime.now().year current_year = datetime.now().year
# current_year = 2022
now_time3 = '' now_time3 = ''
now_time4 = '' now_time4 = ''
now_time = datetime.now().strftime('%Y-%m-%d') now_time = datetime.now().strftime('%Y-%m-%d')
...@@ -1697,7 +1679,6 @@ def areal_project(): ...@@ -1697,7 +1679,6 @@ def areal_project():
if not data_time: if not data_time:
project_obj = ProjectManagement.query.filter( project_obj = ProjectManagement.query.filter(
ProjectManagement.district == district if district else text(''), ProjectManagement.district == district if district else text(''),
# ProjectManagement.sign_time.like('%{}%'.format(str(current_year))),
ProjectManagement.sign_time < now_time1, ProjectManagement.sign_time < now_time1,
ProjectManagement.sign_time >= now_time, ProjectManagement.sign_time >= now_time,
ProjectManagement.is_delete == 0 ProjectManagement.is_delete == 0
...@@ -1705,7 +1686,6 @@ def areal_project(): ...@@ -1705,7 +1686,6 @@ def areal_project():
else: else:
project_obj = ProjectManagement.query.filter( project_obj = ProjectManagement.query.filter(
ProjectManagement.district == district if district else text(''), ProjectManagement.district == district if district else text(''),
# ProjectManagement.sign_time.like('%{}%'.format(str(current_year))),
ProjectManagement.sign_time < now_time4 if now_time4 else text(''), ProjectManagement.sign_time < now_time4 if now_time4 else text(''),
ProjectManagement.sign_time >= now_time3, ProjectManagement.sign_time >= now_time3,
ProjectManagement.is_delete == 0 ProjectManagement.is_delete == 0
......
...@@ -1705,7 +1705,7 @@ class InvestmentInformation(db.Model): ...@@ -1705,7 +1705,7 @@ class InvestmentInformation(db.Model):
flag = db.Column(db.Integer, comment='类型 1数据通报, 2工作动态') flag = db.Column(db.Integer, comment='类型 1数据通报, 2工作动态')
time = db.Column(db.String(100), default='', comment='时间段') time = db.Column(db.String(100), default='', comment='时间段')
source = db.Column(db.String(20), default='', comment='来源') source = db.Column(db.String(20), default='', comment='来源')
content = db.Column(db.Text, comment='正文') content = db.Column(db.String(255), comment='正文')
# [小程序]客户咨询信息表 # [小程序]客户咨询信息表
......
...@@ -78,9 +78,10 @@ def data_notification(): ...@@ -78,9 +78,10 @@ def data_notification():
try: try:
respose = requests.get(url, headers=headers) respose = requests.get(url, headers=headers)
respose.encoding = 'utf-8' respose.encoding = 'utf-8'
html_etree = ''
if respose.status_code == 200: if respose.status_code == 200:
html_etree = etree.HTML(respose.text) html_etree = etree.HTML(respose.text)
handeled_html_str = etree.tostring(html_etree).decode() # handeled_html_str = etree.tostring(html_etree).decode()
# print(handeled_html_str) # print(handeled_html_str)
content_name_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[@class="list_newstitle"]/a/text()') content_name_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[@class="list_newstitle"]/a/text()')
content_url_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[@class="list_newstitle"]/a/@href') content_url_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[@class="list_newstitle"]/a/@href')
...@@ -88,9 +89,21 @@ def data_notification(): ...@@ -88,9 +89,21 @@ def data_notification():
i = 0 i = 0
for content_name in content_name_list: for content_name in content_name_list:
content_url = content_url_list[i].replace("./", 'http://zsj.jcgov.gov.cn/sjtb/sjtb/'),
respose = requests.get(content_url[0], headers=headers)
respose.encoding = 'utf-8'
html_etree1 = ''
if respose.status_code == 200:
html_etree1 = etree.HTML(respose.text)
# handeled_html_str1 = etree.tostring(html_etree).decode()
# print(handeled_html_str1)
content = html_etree1.xpath('//table[1]')[2]
result = etree.tostring(content, encoding='utf-8').decode()
data_dic = { data_dic = {
"content_name": content_name, "content_name": content_name,
"content_url": content_url_list[i].replace('./', 'http://zsj.jcgov.gov.cn/sjtb/sjtb/'), # "content_url": content_url_list[i].replace('./', 'http://zsj.jcgov.gov.cn/sjtb/sjtb/'),
"content": result,
"time": time_list[i][1:-1] "time": time_list[i][1:-1]
} }
data_list.append(data_dic) data_list.append(data_dic)
...@@ -106,16 +119,15 @@ def data_notification(): ...@@ -106,16 +119,15 @@ def data_notification():
content_name = data['content_name'] content_name = data['content_name']
inform_obj = InvestmentInformation.query.filter_by(flag=2, name=content_name).first() inform_obj = InvestmentInformation.query.filter_by(flag=2, name=content_name).first()
if inform_obj: if inform_obj:
inform_obj.time = data['time']
inform_obj.source = '晋城市投资促进中心'
db.session.commit()
continue continue
inform_obj = InvestmentInformation() inform_obj = InvestmentInformation()
inform_obj.name = data['content_name'] inform_obj.name = data['content_name']
inform_obj.flag = 2 inform_obj.flag = 2
inform_obj.content = data['content']
inform_obj.time = data['time'] inform_obj.time = data['time']
inform_obj.source = '晋城市投资促进中心' inform_obj.source = '晋城市投资促进中心'
inform_obj.info = '' inform_obj.info = ''
inform_obj.time = data['time']
db.session.add(inform_obj) db.session.add(inform_obj)
db.session.commit() db.session.commit()
return jsonify(code=RET.OK, msg="获取成功", data=data_list) return jsonify(code=RET.OK, msg="获取成功", data=data_list)
...@@ -160,7 +172,7 @@ def work_trend(): ...@@ -160,7 +172,7 @@ def work_trend():
'//div[@class="view TRS_UEDITOR trs_paper_default trs_web"]/p/text()') '//div[@class="view TRS_UEDITOR trs_paper_default trs_web"]/p/text()')
content_info1 = '' content_info1 = ''
for content_info in content_info_list: for content_info in content_info_list:
content_info1 += content_info content_info1 = content_info1 + '<br>' + content_info
data_dic = { data_dic = {
"content_name": content_name, "content_name": content_name,
"content_info": content_info1, "content_info": content_info1,
......
...@@ -4,3 +4,4 @@ from flask import Blueprint ...@@ -4,3 +4,4 @@ from flask import Blueprint
api_xiaocx = Blueprint("api_xiaocx", __name__) api_xiaocx = Blueprint("api_xiaocx", __name__)
from . import view from . import view
from . import update_investment_information
import requests
from flask import jsonify, current_app
from lxml import etree
from apps.models import *
from apps.utils.response_code import RET
from apps import db
from apps.view_xiaocx import api_xiaocx
# 数据通报
@api_xiaocx.route("/DataNotification", methods=["GET"])
def data_notification():
page_html_list = [
"index.shtml", # 首页
"index_1.shtml", # 第2页
"index_2.shtml", # 第3页
"index_3.shtml", # 第4页
"index_4.shtml", # 第5页
"index_5.shtml", # 第6页
"index_6.shtml", # 第7页
]
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54'}
data_list = []
for page_index in page_html_list:
url = "http://zsj.jcgov.gov.cn/sjtb/sjtb/{}".format(page_index)
try:
respose = requests.get(url, headers=headers)
respose.encoding = 'utf-8'
html_etree = ''
if respose.status_code == 200:
html_etree = etree.HTML(respose.text)
# handeled_html_str = etree.tostring(html_etree).decode()
# print(handeled_html_str)
content_name_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[@class="list_newstitle"]/a/text()')
content_url_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[@class="list_newstitle"]/a/@href')
time_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[2]/text()')
i = 0
for content_name in content_name_list:
content_url = content_url_list[i].replace("./", 'http://zsj.jcgov.gov.cn/sjtb/sjtb/'),
respose = requests.get(content_url[0], headers=headers)
respose.encoding = 'utf-8'
html_etree1 = ''
if respose.status_code == 200:
html_etree1 = etree.HTML(respose.text)
# handeled_html_str1 = etree.tostring(html_etree).decode()
# print(handeled_html_str1)
content = html_etree1.xpath('//table[1]')[2]
result = etree.tostring(content, encoding='utf-8').decode()
data_dic = {
"content_name": content_name,
"content": result,
"time": time_list[i][1:-1]
}
data_list.append(data_dic)
i += 1
continue
continue
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
# 存入数据库
for data in data_list:
content_name = data['content_name']
inform_obj = InvestmentInformation.query.filter_by(flag=2, name=content_name).first()
if inform_obj:
inform_obj.content = data['content']
db.session.commit()
continue
inform_obj = InvestmentInformation()
inform_obj.name = data['content_name']
inform_obj.flag = 2
inform_obj.content = data['content']
inform_obj.time = data['time']
inform_obj.source = '晋城市投资促进中心'
inform_obj.info = ''
inform_obj.time = data['time']
db.session.add(inform_obj)
db.session.commit()
return jsonify(code=RET.OK, msg="入库成功", data=data_list)
# 工作动态
@api_xiaocx.route("/WorkTrend", methods=["GET"])
def work_trend():
page_html_list = ["index.shtml"]
for i in range(1, 25):
html_index = 'index_{}.shtml'.format(i)
page_html_list.append(html_index)
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54'}
data_list = []
for page_index in page_html_list:
url = "http://zsj.jcgov.gov.cn/xwdt/zhxx/{}".format(page_index)
try:
respose = requests.get(url, headers=headers)
respose.encoding = 'utf-8'
if respose.status_code == 200:
html_etree = etree.HTML(respose.text)
# handeled_html_str = etree.tostring(html_etree).decode()
# print(handeled_html_str)
content_name_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[@class="list_newstitle"]/a/text()')
content_url_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[@class="list_newstitle"]/a/@href')
time_list = html_etree.xpath('//div[@class="newslist newslistdixx"]//span[2]/text()')
i = 0
for content_name in content_name_list:
content_url = content_url_list[i].replace('./', 'http://zsj.jcgov.gov.cn/xwdt/zhxx/')
content_html = requests.get(content_url, headers=headers)
content_html.encoding = 'utf-8'
if content_html.status_code == 200:
html_etree1 = etree.HTML(content_html.text)
# handeled_html_str = etree.tostring(html_etree1).decode()
# print(handeled_html_str)
content_info_list = html_etree1.xpath(
'//div[@class="view TRS_UEDITOR trs_paper_default trs_web"]/p/text()')
content_info1 = ''
for content_info in content_info_list:
content_info1 = content_info1 + '<br>' + content_info
data_dic = {
"content_name": content_name,
"content_info": content_info1,
"time": time_list[i][1:-1]
}
data_list.append(data_dic)
i += 1
continue
continue
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
# # 存入数据库
for data in data_list:
content_name = data['content_name']
inform_obj = InvestmentInformation.query.filter_by(flag=1, name=content_name).first()
if inform_obj:
inform_obj.content = data['content_info']
db.session.commit()
continue
inform_obj = InvestmentInformation()
inform_obj.name = data['content_name']
inform_obj.flag = 1
inform_obj.time = data['time']
inform_obj.source = '晋城市投资促进中心'
inform_obj.content = data['content_info']
db.session.add(inform_obj)
db.session.commit()
return jsonify(code=RET.OK, msg="入库成功", data=data_list)
...@@ -363,7 +363,6 @@ def information(): ...@@ -363,7 +363,6 @@ def information():
"name": inform_obj.name, "name": inform_obj.name,
"time": inform_obj.time, "time": inform_obj.time,
"source": inform_obj.source, "source": inform_obj.source,
"info": inform_obj.content,
} for inform_obj in inform_obj_list] } for inform_obj in inform_obj_list]
except Exception as e: except Exception as e:
...@@ -384,8 +383,7 @@ def information_detail(): ...@@ -384,8 +383,7 @@ def information_detail():
inform_obj = InvestmentInformation.query.get(_id) inform_obj = InvestmentInformation.query.get(_id)
else: # 最新一条 else: # 最新一条
inform_obj = InvestmentInformation.query.order_by( inform_obj = InvestmentInformation.query.order_by(
InvestmentInformation.id.desc() InvestmentInformation.id.desc()).all()[-1]
).all()[-1]
data = { data = {
"name": inform_obj.name, "name": inform_obj.name,
......
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