分享一个基于python新闻订阅与分享平台flask新闻发布系统(源码、调试、LW、开题、PPT)

💕💕作者:计算机源码社
💕💕个人简介:本人 八年开发经验,擅长Java、Python、PHP、.NET、Node.js、Android、微信小程序、爬虫、大数据、机器学习等,大家有这一块的问题可以一起交流!
💕💕学习资料、程序开发、技术解答、文档报告
💕💕如需要源码,可以扫取文章下方二维码联系咨询

💕💕Java项目
💕💕微信小程序项目
💕💕Android项目
💕💕Python项目
💕💕PHP项目
💕💕ASP.NET项目
💕💕Node.js项目
💕💕选题推荐

项目实战|基于python的新闻订阅与分享平台flask项目

文章目录

  • 1、选题背景
  • 2、研究目的和意义
  • 3、系统研究内容
  • 4、系统页面设计
  • 5、参考文献
  • 6、核心代码

1、选题背景

   随着互联网的迅猛发展和信息化时代的到来,新闻传播的方式发生了深刻的变化。传统的新闻获取方式已经无法满足用户对即时性、互动性和个性化的需求,特别是在移动互联网的影响下,用户对新闻的获取方式和内容呈现提出了更高的要求。在此背景下,基于Python的新闻订阅与分享平台应运而生,旨在为用户提供一个便捷、高效的新闻获取与交流平台,以应对当前新闻传播方式的变革。

2、研究目的和意义

  本项目的开发旨在构建一个集新闻订阅、分享、评论与互动于一体的平台,为用户提供多样化的新闻内容与交互功能。通过该平台,用户可以根据自己的兴趣定制新闻内容,及时获取最新的新闻资讯,并能与其他用户进行交流与分享。管理员能够通过后台管理系统有效地管理新闻内容、用户信息及平台数据,从而提升平台的运营效率和用户体验。

   基于Python的新闻订阅与分享平台的开发具有重要的现实意义,它为用户提供了个性化新闻获取与社交分享的途径,提升了用户获取信息的效率。平台的开发展示了Python、Flask与Vue等技术在实际应用中的集成与运用,具有较高的学习和研究价值。最后,通过对平台数据的可视化分析,能够为新闻行业提供数据支持,帮助其优化内容分发策略,提高新闻传播的精准度与影响力。

3、系统研究内容

本系统主要研究基于Python的新闻订阅与分享平台的设计与实现过程,系统的需求分析将全面探讨用户需求和功能需求,确定平台的主要功能模块,包括用户管理、新闻类型管理、新闻信息管理、排行榜管理、留言板管理、新闻论坛管理及多种可视化报表的生成。本文将详细描述系统架构的设计,介绍如何使用Python和Flask进行后端开发、如何利用Vue实现前端交互,以及MySQL在数据存储与管理中的应用。

系统将深入探讨平台各功能模块的实现细节,包括用户管理模块的用户注册、登录与权限分配,新闻信息管理模块的新闻发布、编辑与删除,排行榜模块的新闻阅读量统计与排行展示,以及留言板和论坛模块的用户互动功能。还将研究通过数据可视化技术生成新闻总数、排行榜、用户统计等报表的具体实现方法,帮助管理员更好地理解平台运营情况。

4、系统页面设计

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
如需要源码,可以扫取文章下方二维码联系咨询

5、参考文献

[1]傅婷婷.全媒体新闻生产管理系统的设计与实现[J].广播与电视技术,2023,50(09):77-81.DOI:10.16171/j.cnki.rtbe.20230009014.
[2]蒋先梅.基于MVC模式的新闻管理系统的设计与实现[J].无线互联科技,2023,20(11):77-79.
[3]和占全,李晓明,冯汝结,等.基于信创的互联网新闻数据信息安全管理系统的设计与实现[J].网络安全技术与应用,2023,(03):94-96.
[4]申晋祥,鲍美英.基于Android的家校交流平台的设计与实现[J].电子元器件与信息技术,2022,6(02):182-184+187.DOI:10.19772/j.cnki.2096-4455.2022.2.070.
[5]梁宽宏.基于MVC架构的校园新闻发布管理系统[J].电子世界,2021,(18):182-183.DOI:10.19353/j.cnki.dzsj.2021.18.078.
[6]闫慧珍.基于数据爬取的新闻宣传信息系统的设计与实现[D].中北大学,2021. DOI:10.27470/d.cnki.ghbgc.2021.000936.
[7]王钦坤,文档编撰管理系统V1.0.江西省,江西和壹科技有限公司,2021-04-01.
[8]陆岫昶.企业新闻网稿件业务流程管理系统设计[J].数字技术与应用,2021,39(03):117-119.DOI:10.19695/j.cnki.cn12-1369.2021.03.39.
[9]牛怀岗,林关成.基于SSM框架的新闻发布管理系统设计与实现[J].现代电子技术,2020,43(21):127-131.DOI:10.16652/j.issn.1004-373x.2020.21.030.
[10]孙雪兰,华翔采购管理系统V1.0.湖南省,华翔翔能科技股份有限公司,2020-08-01.
[11]陈亮亮.基于大数据平台的通讯数据管理系统研究与应用[D].湖北工业大学,2020. DOI:10.27131/d.cnki.ghugc.2020.000506.
[12]于洪奇,陈卉,叶兴茂,等.自然资源部新闻宣传管理系统建设与应用[J].国土资源信息化,2020,(03):39-43.
[13]段鑫.火电厂检修管理系统的设计与实现[D].西安电子科技大学,2020. DOI:10.27389/d.cnki.gxadu.2020.003140.
[14]任超.面向互联网的新闻管理系统设计与实现[D].山东大学,2020. DOI:10.27272/d.cnki.gshdu.2020.002938.
[15]张立新.基于Android的新闻智能发布及管理系统[J].电脑编程技巧与维护,2020,(05):69-72.DOI:10.16184/j.cnki.comprg.2020.05.024.
[16]韩旭.基于WEB的新闻管理系统的设计与实现[J].电子世界,2020,(03):204-205.DOI:10.19353/j.cnki.dzsj.2020.03.118.
[17]宋江浩,世豪能量管理系统软件V1.0.陕西省,西安世豪汇科智能科技有限公司,2020-02-01.
[18]袁文涛,微擎新闻管理系统V2.5.安徽省,宿州市微擎云计算有限公司,2020-01-14.
[19]牛帆,黄婷婷,史铭.新闻采编业务管理系统的设计与实践[C]//中国新闻技术工作者联合会.中国新闻技术工作者联合会2019年学术年会论文集.新华社技术局;,2019:7. DOI:10.26914/c.cnkihy.2019.021708.
[20]仉允苇.石油新闻管理系统的设计与实现[D].西安电子科技大学,2019. DOI:10.27389/d.cnki.gxadu.2019.003275.

6、核心代码

# coding:utf-8
__author__ = "ila"import logging, os, json, configparser
import time
from datetime import datetime
from werkzeug.utils import redirectfrom flask import request, jsonify,session
from sqlalchemy.sql import func,and_,or_,case
from sqlalchemy import cast, Integer,Float
from api.models.brush_model import *
from . import main_bp
from utils.codes import *
from utils.jwt_auth import Auth
from configs import configs
from utils.helper import *
import random
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
from email.header import Header
from utils.baidubce_api import BaiDuBce
from api.models.config_model import config# 注册接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/register", methods=['POST'])
def pythonf701pot2_xinwenxinxi_register():if request.method == 'POST':msg = {'code': normal_code, 'message': 'success', 'data': [{}]}req_dict = session.get("req_dict")error = xinwenxinxi.createbyreq(xinwenxinxi, xinwenxinxi, req_dict)if error!=None:msg['code'] = crud_error_codemsg['msg'] = "注册用户已存在"return jsonify(msg)# 登录接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/login", methods=['GET','POST'])
def pythonf701pot2_xinwenxinxi_login():if request.method == 'GET' or request.method == 'POST':msg = {"code": normal_code, "msg": "success", "data": {}}req_dict = session.get("req_dict")req_model = session.get("req_dict")try:del req_model['role']except:passdatas = xinwenxinxi.getbyparams(xinwenxinxi, xinwenxinxi, req_model)if not datas:msg['code'] = password_error_codemsg['msg']='密码错误或用户不存在'return jsonify(msg)req_dict['id'] = datas[0].get('id')try:del req_dict['mima']except:passreturn Auth.authenticate(Auth, xinwenxinxi, req_dict)# 登出接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/logout", methods=['POST'])
def pythonf701pot2_xinwenxinxi_logout():if request.method == 'POST':msg = {"msg": "退出成功","code": 0}req_dict = session.get("req_dict")return jsonify(msg)# 重置密码接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/resetPass", methods=['POST'])
def pythonf701pot2_xinwenxinxi_resetpass():''''''if request.method == 'POST':msg = {"code": normal_code, "msg": "success"}req_dict = session.get("req_dict")if req_dict.get('mima') != None:req_dict['mima'] = '123456'error = xinwenxinxi.updatebyparams(xinwenxinxi, xinwenxinxi, req_dict)if error != None:msg['code'] = crud_error_codemsg['msg'] = errorelse:msg['msg'] = '密码已重置为:123456'return jsonify(msg)# 获取会话信息接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/session", methods=['GET'])
def pythonf701pot2_xinwenxinxi_session():''''''if request.method == 'GET':msg = {"code": normal_code, "data": {}}req_dict={"id":session.get('params').get("id")}msg['data']  = xinwenxinxi.getbyparams(xinwenxinxi, xinwenxinxi, req_dict)[0]return jsonify(msg)# 分类接口(后端)
@main_bp.route("/pythonf701pot2/xinwenxinxi/page", methods=['GET'])
def pythonf701pot2_xinwenxinxi_page():''''''if request.method == 'GET':msg = {"code": normal_code, "msg": "success",  "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}req_dict = session.get("req_dict")userinfo = session.get("params")try:__hasMessage__=xinwenxinxi.__hasMessage__except:__hasMessage__=Noneif __hasMessage__ and __hasMessage__!="否":tablename=session.get("tablename")if tablename!="users" and session.get("params")!=None and xinwenxinxi!='chat':req_dict["userid"]=session.get("params").get("id")tablename=session.get("tablename")if tablename=="users" :try:passexcept:passelse:mapping_str_to_object = {}for model in Base_model._decl_class_registry.values():if hasattr(model, '__tablename__'):mapping_str_to_object[model.__tablename__] = modeltry:__isAdmin__=mapping_str_to_object[tablename].__isAdmin__except:__isAdmin__=Nonetry:__authSeparate__ =mapping_str_to_object[tablename].__authSeparate__except:__authSeparate__ = Noneif __isAdmin__!="是" and __authSeparate__ == "是" and session.get("params")!=None:req_dict["userid"]=session.get("params").get("id")else:try:del req_dict["userid"]except:pass# 当前表也是有管理员权限的表if  __isAdmin__ == "是" and 'xinwenxinxi' != 'forum':if req_dict.get("userid") and 'xinwenxinxi' != 'chat':del req_dict["userid"]else:#非管理员权限的表,判断当前表字段名是否有useridif tablename!="users" and 'xinwenxinxi'[:7]!='discuss'and "userid" in xinwenxinxi.getallcolumn(xinwenxinxi,xinwenxinxi):req_dict["userid"] = session.get("params").get("id")clause_args = []or_clauses = or_(*clause_args)msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \msg['data']['pageSize']  = xinwenxinxi.page(xinwenxinxi, xinwenxinxi, req_dict, or_clauses)return jsonify(msg)# 排序接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/autoSort", methods=['GET'])
def pythonf701pot2_xinwenxinxi_autosort():''''''if request.method == 'GET':msg = {"code": normal_code, "msg": "success",  "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}req_dict = session.get("req_dict")req_dict['sort']='clicktime'req_dict['order']='desc'try:__browseClick__= xinwenxinxi.__browseClick__except:__browseClick__=Noneif __browseClick__ =='是':req_dict['sort']='clicknum'elif __browseClick__ =='时长':req_dict['sort']='browseduration'else:req_dict['sort']='clicktime'msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \msg['data']['pageSize']  = xinwenxinxi.page(xinwenxinxi, xinwenxinxi, req_dict)return jsonify(msg)#查询单条数据
@main_bp.route("/pythonf701pot2/xinwenxinxi/query", methods=['GET'])
def pythonf701pot2_xinwenxinxi_query():if request.method == 'GET':msg = {"code": normal_code, "msg": "success",  "data":{}}req_dict = session.get("req_dict")query = db.session.query(xinwenxinxi)for key, value in req_dict.items():query = query.filter(getattr(xinwenxinxi, key) == value)query_result = query.first()query_result.__dict__.pop('_sa_instance_state', None)msg['data'] = query_result.__dict__return jsonify(msg)# 分页接口(前端)
@main_bp.route("/pythonf701pot2/xinwenxinxi/list", methods=['GET'])
def pythonf701pot2_xinwenxinxi_list():''''''if request.method == 'GET':msg = {"code": normal_code, "msg": "success",  "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}req_dict = session.get("req_dict")if req_dict.__contains__('vipread'):del req_dict['vipread']userinfo = session.get("params")try:__foreEndListAuth__=xinwenxinxi.__foreEndListAuth__except:__foreEndListAuth__=Noneif __foreEndListAuth__ and __foreEndListAuth__!="否":tablename=session.get("tablename")if tablename!="users" and session.get("params")!=None:req_dict['userid']=session.get("params").get("id")tablename=session.get("tablename")if 'luntan' in 'xinwenxinxi':if 'userid' in req_dict.keys():del req_dict["userid"]if 'discuss' in 'xinwenxinxi':if 'userid' in req_dict.keys():del req_dict["userid"]msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \msg['data']['pageSize']  = xinwenxinxi.page(xinwenxinxi, xinwenxinxi, req_dict)return jsonify(msg)# 保存接口(后端)
@main_bp.route("/pythonf701pot2/xinwenxinxi/save", methods=['POST'])
def pythonf701pot2_xinwenxinxi_save():''''''if request.method == 'POST':msg = {"code": normal_code, "msg": "success", "data": {}}req_dict = session.get("req_dict")for key in req_dict:if req_dict[key] == '':req_dict[key] = Noneerror= xinwenxinxi.createbyreq(xinwenxinxi, xinwenxinxi, req_dict)if error!=None:msg['code'] = crud_error_codemsg['msg'] = errorreturn jsonify(msg)# 添加接口(前端)
@main_bp.route("/pythonf701pot2/xinwenxinxi/add", methods=['POST'])
def pythonf701pot2_xinwenxinxi_add():''''''if request.method == 'POST':msg = {"code": normal_code, "msg": "success", "data": {}}req_dict = session.get("req_dict")try:__foreEndListAuth__=xinwenxinxi.__foreEndListAuth__except:__foreEndListAuth__=Noneif __foreEndListAuth__ and __foreEndListAuth__!="否":tablename=session.get("tablename")if tablename!="users":req_dict['userid']=session.get("params").get("id")error= xinwenxinxi.createbyreq(xinwenxinxi, xinwenxinxi, req_dict)if error!=None:msg['code'] = crud_error_codemsg['msg'] = errorreturn jsonify(msg)# 踩、赞接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/thumbsup/<id_>", methods=['GET'])
def pythonf701pot2_xinwenxinxi_thumbsup(id_):''''''if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": {}}req_dict = session.get("req_dict")id_=int(id_)type_=int(req_dict.get("type",0))rets=xinwenxinxi.getbyid(xinwenxinxi, xinwenxinxi,id_)update_dict={"id":id_,}if type_==1:#赞update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1elif type_==2:#踩update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1error = xinwenxinxi.updatebyparams(xinwenxinxi, xinwenxinxi, update_dict)if error!=None:msg['code'] = crud_error_codemsg['msg'] = errorreturn jsonify(msg)# 获取详情信息(后端)
@main_bp.route("/pythonf701pot2/xinwenxinxi/info/<id_>", methods=['GET'])
def pythonf701pot2_xinwenxinxi_info(id_):''''''if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": {}}data = xinwenxinxi.getbyid(xinwenxinxi, xinwenxinxi, int(id_))if len(data)>0:msg['data']=data[0]#浏览点击次数try:__browseClick__= xinwenxinxi.__browseClick__except:__browseClick__=Noneif __browseClick__  and  "clicknum"  in xinwenxinxi.__table__.columns:click_dict={"id":int(id_),"clicknum":str(int(data[0].get("clicknum") or 0)+1)}ret=xinwenxinxi.updatebyparams(xinwenxinxi,xinwenxinxi,click_dict)if ret!=None:msg['code'] = crud_error_codemsg['msg'] = retreturn jsonify(msg)# 获取详情信息(前端)
@main_bp.route("/pythonf701pot2/xinwenxinxi/detail/<id_>", methods=['GET'])
def pythonf701pot2_xinwenxinxi_detail(id_):''''''if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": {}}data = xinwenxinxi.getbyid(xinwenxinxi, xinwenxinxi, int(id_))if len(data)>0:msg['data']=data[0]#浏览点击次数try:__browseClick__= xinwenxinxi.__browseClick__except:__browseClick__=Noneif __browseClick__ and "clicknum" in xinwenxinxi.__table__.columns:click_dict={"id":int(id_),"clicknum":str(int(data[0].get("clicknum") or 0)+1)}ret=xinwenxinxi.updatebyparams(xinwenxinxi,xinwenxinxi,click_dict)if ret!=None:msg['code'] = crud_error_codemsg['msg'] = retreturn jsonify(msg)# 更新接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/update", methods=['POST'])
def pythonf701pot2_xinwenxinxi_update():''''''if request.method == 'POST':msg = {"code": normal_code, "msg": "success", "data": {}}req_dict = session.get("req_dict")if req_dict.get("mima") and "mima" not in xinwenxinxi.__table__.columns :del req_dict["mima"]if req_dict.get("password") and "password" not in xinwenxinxi.__table__.columns :del req_dict["password"]try:del req_dict["clicknum"]except:passerror = xinwenxinxi.updatebyparams(xinwenxinxi, xinwenxinxi, req_dict)if error!=None:msg['code'] = crud_error_codemsg['msg'] = errorreturn jsonify(msg)# 删除接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/delete", methods=['POST'])
def pythonf701pot2_xinwenxinxi_delete():''''''if request.method == 'POST':msg = {"code": normal_code, "msg": "success", "data": {}}req_dict = session.get("req_dict")error=xinwenxinxi.delete(xinwenxinxi,req_dict)if error!=None:msg['code'] = crud_error_codemsg['msg'] = errorreturn jsonify(msg)# 投票接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/vote/<int:id_>", methods=['POST'])
def pythonf701pot2_xinwenxinxi_vote(id_):''''''if request.method == 'POST':msg = {"code": normal_code, "msg": "success"}data= xinwenxinxi.getbyid(xinwenxinxi, xinwenxinxi, int(id_))for i in data:votenum=i.get('votenum')if votenum!=None:params={"id":int(id_),"votenum":votenum+1}error=xinwenxinxi.updatebyparams(xinwenxinxi,xinwenxinxi,params)if error!=None:msg['code'] = crud_error_codemsg['msg'] = errorreturn jsonify(msg)# 分组统计接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/group/<columnName>", methods=['GET'])
def pythonf701pot2_xinwenxinxi_group(columnName):'''分组统计接口'''if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": {}}req_dict = session.get("req_dict")userinfo = session.get("params")msg['data'] = xinwenxinxi.groupbycolumnname(xinwenxinxi,xinwenxinxi,columnName,req_dict)msg['data'] = msg['data'][:10]msg['data'] = [ {**i,columnName:str(i[columnName])} if columnName in i else i for i in msg['data']]json_filename='xinwenxinxi'+f'_group_{columnName}.json'where = ' where 1 = 1 'sql = "SELECT COUNT(*) AS total, " + columnName + " FROM xinwenxinxi " + where + " GROUP BY " + columnNamereturn jsonify(msg)# 按值统计接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/value/<xColumnName>/<yColumnName>", methods=['GET'])
def pythonf701pot2_xinwenxinxi_value(xColumnName, yColumnName):'''按值统计接口,{"code": 0,"data": [{"total": 10.0,"shangpinleibie": "aa"},{"total": 20.0,"shangpinleibie": "bb"},{"total": 15.0,"shangpinleibie": "cc"}]}'''if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": {}}req_dict = session.get("req_dict")userinfo = session.get("params")msg['data'] = xinwenxinxi.getvaluebyxycolumnname(xinwenxinxi,xinwenxinxi,xColumnName,yColumnName,req_dict)msg['data'] = msg['data'][:10]return jsonify(msg)# 按日期统计接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/value/<xColumnName>/<yColumnName>/<timeStatType>", methods=['GET'])
def pythonf701pot2_xinwenxinxi_value_riqi(xColumnName, yColumnName, timeStatType):'''按日期统计接口'''if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": {}}userinfo = session.get("params")where = ' where 1 = 1 'sql = ''if timeStatType == '日':sql = "SELECT DATE_FORMAT({0}, '%Y-%m-%d') {0}, sum({1}) total FROM xinwenxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y-%m-%d')".format(xColumnName, yColumnName, where, '%Y-%m-%d')if timeStatType == '月':sql = "SELECT DATE_FORMAT({0}, '%Y-%m') {0}, sum({1}) total FROM xinwenxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y-%m')".format(xColumnName, yColumnName, where, '%Y-%m')if timeStatType == '年':sql = "SELECT DATE_FORMAT({0}, '%Y') {0}, sum({1}) total FROM xinwenxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y')".format(xColumnName, yColumnName, where, '%Y')data = db.session.execute(sql)data = data.fetchall()results = []for i in range(len(data)):result = {xColumnName: decimalEncoder(data[i][0]),'total': decimalEncoder(data[i][1])}results.append(result)msg['data'] = resultsjson_filename='xinwenxinxi'+f'_value_{xColumnName}_{yColumnName}.json'return jsonify(msg)# 按值统计(多)
@main_bp.route("/pythonf701pot2/xinwenxinxi/valueMul/<xColumnName>", methods=['GET'])
def pythonf701pot2_xinwenxinxi_valueMul(xColumnName):if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": []}req_dict = session.get("req_dict")userinfo = session.get("params")where = ' where 1 = 1 'for item in req_dict['yColumnNameMul'].split(','):sql = "SELECT {0}, sum({1}) AS total FROM xinwenxinxi {2} GROUP BY {0} LIMIT 10".format(xColumnName, item, where)L = []data = db.session.execute(sql)data = data.fetchall() for i in range(len(data)):result = {xColumnName: decimalEncoder(data[i][0]),'total': decimalEncoder(data[i][1])}L.append(result)msg['data'].append(L)return jsonify(msg)# 按值统计(多)
@main_bp.route("/pythonf701pot2/xinwenxinxi/valueMul/<xColumnName>/<timeStatType>", methods=['GET'])
def pythonf701pot2_xinwenxinxi_valueMul_time(xColumnName,timeStatType):if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": []}req_dict = session.get("req_dict")userinfo = session.get("params")where = ' where 1 = 1 'for item in req_dict['yColumnNameMul'].split(','):sql = ''if timeStatType == '日':sql = "SELECT DATE_FORMAT({0}, '%Y-%m-%d') {0}, sum({1}) total FROM xinwenxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y-%m-%d') LIMIT 10".format(xColumnName, item, where, '%Y-%m-%d')if timeStatType == '月':sql = "SELECT DATE_FORMAT({0}, '%Y-%m') {0}, sum({1}) total FROM xinwenxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y-%m') LIMIT 10".format(xColumnName, item, where, '%Y-%m')if timeStatType == '年':sql = "SELECT DATE_FORMAT({0}, '%Y') {0}, sum({1}) total FROM xinwenxinxi {2} GROUP BY DATE_FORMAT({0}, '%Y') LIMIT 10".format(xColumnName, item, where, '%Y')L = []data = db.session.execute(sql)data = data.fetchall() for i in range(len(data)):result = {xColumnName: decimalEncoder(data[i][0]),'total': decimalEncoder(data[i][1])}L.append(result)msg['data'].append(L)return jsonify(msg)import base64
import copy# 推荐算法接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/autoSort2", methods=['GET'])
def pythonf701pot2_xinwenxinxi_autoSort2():if request.method == 'GET':leixing = set()req_dict = session.get("req_dict")userinfo = session.get("params")auth_header = request.headers.get('token')if auth_header:auth_token = copy.deepcopy(auth_header)decode_str = base64.b64decode(auth_token).decode("utf8")decode_dict = eval(decode_str)tablename2 = decode_dict.get("tablename")if tablename2 == "yonghu":sql = "select xinwenbiaoqian from yonghu where id = "+str(userinfo.get("id"))+" order by addtime desc"try:data = db.session.execute(sql)rows = data.fetchall()for row in rows:for item in row:if item != None:for i in item.split(','):leixing.add(i)except:leixing = set()L = []where = " AND ".join([f"{key} = '{value}'" for key, value in req_dict.items() if key!="page" and key!="limit" and key!="order"and key!="sort"])if where:sql = f'''SELECT * FROM (SELECT * FROM xinwenxinxi WHERE {where}) AS table1 WHERE xinwenbiaoqian IN ('{"','".join(leixing)}') union all SELECT * FROM (SELECT * FROM xinwenxinxi WHERE {where}) AS table1 WHERE xinwenbiaoqian NOT IN ('{"','".join(leixing)}')'''else:sql ="select * from xinwenxinxi where xinwenbiaoqian in ('%s"%("','").join(leixing)+"') union all select * from xinwenxinxi where xinwenbiaoqian not in('%s"%("','").join(leixing)+"')"data = db.session.execute(sql)data_dict = [dict(zip(result.keys(), result)) for result in data.fetchall()]for online_dict in data_dict:for key in online_dict:if 'datetime.datetime' in str(type(online_dict[key])):online_dict[key] = online_dict[key].strftime("%Y-%m-%d %H:%M:%S")elif 'datetime' in str(type(online_dict[key])):online_dict[key] = online_dict[key].strftime("%Y-%m-%d %H:%M:%S")else:passL.append(online_dict)return jsonify({"code": 0, "msg": '',  "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":5,"list": L[0:int(req_dict['limit'])]}})# 总数量
@main_bp.route("/pythonf701pot2/xinwenxinxi/count", methods=['GET'])
def pythonf701pot2_xinwenxinxi_count():''''''if request.method == 'GET':msg = {"code": normal_code, "msg": "success",  "data": 0}req_dict = session.get("req_dict")userinfo = session.get("params")msg['data']  = xinwenxinxi.count(xinwenxinxi, xinwenxinxi, req_dict)return jsonify(msg)# 统计接口
@main_bp.route("/pythonf701pot2/xinwenxinxi/remind/<columnName>/<type>", methods=['GET'])  #
def pythonf701pot2_xinwenxinxi_remind(columnName,type):''''''if request.method == 'GET':msg = {"code": normal_code, 'count': 0}# 组合查询参数params = session.get("req_dict")remindstart = 0remindend =9999990if int(type)==1:#数字if params.get('remindstart') == None and params.get('remindend') != None:remindstart = 0remindend = int(params['remindend'])elif params.get('remindstart') != None and params.get('remindend') == None:remindstart = int(params['remindstart'])remindend = 999999elif params.get('remindstart') == None and params.get('remindend') == None:remindstart = 0remindend = 999999else:remindstart = params.get('remindstart')remindend =  params.get('remindend')elif int(type)==2:#日期current_time=int(time.time())if params.get('remindstart') == None and params.get('remindend') != None:starttime=current_time-60*60*24*365*2params['remindstart'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(starttime))endtime=current_time+60*60*24*params.get('remindend')params['remindend'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(endtime))elif params.get('remindstart') != None and params.get('remindend') == None:starttime= current_time - 60 * 60 * 24 * params.get('remindstart')params['remindstart']=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(starttime))endtime=current_time+60*60*24*365*2params['remindend'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(endtime))elif params.get('remindstart') == None and params.get('remindend') == None:starttime = current_time - 60 * 60 * 24 * 365 * 2params['remindstart'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(starttime))endtime = current_time + 60 * 60 * 24 * 365 * 2params['remindend'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(endtime))data = xinwenxinxi.getbetweenparams(xinwenxinxi,xinwenxinxi,columnName,{"remindStart": remindstart,"remindEnd": remindend})msg['count'] = len(data)return jsonify(msg)#分类列表
@main_bp.route("/pythonf701pot2/xinwenxinxi/lists", methods=['GET'])
def pythonf701pot2_xinwenxinxi_lists():if request.method == 'GET':msg = {"code": normal_code, "msg": "success", "data": []}list,_,_,_,_ = xinwenxinxi.page(xinwenxinxi,xinwenxinxi,{})msg['data'] = listreturn jsonify(msg)

💕💕作者:计算机源码社
💕💕个人简介:本人 八年开发经验,擅长Java、Python、PHP、.NET、Node.js、Android、微信小程序、爬虫、大数据、机器学习等,大家有这一块的问题可以一起交流!
💕💕学习资料、程序开发、技术解答、文档报告
💕💕如需要源码,可以扫取文章下方二维码联系咨询


http://www.ppmy.cn/news/1517220.html

相关文章

oracle数据库主机监控脚本

###主机检查#### #!/bin/bash echo banner hostname echo 主机名&#xff08;hostname&#xff09; hostname echo echo 登陆信息 who am i echo echo 收集时间&#xff08;date&#xff09; date "%Y年%m月%d日 %H:%M:%S 星期%w" echo echo 系统内核信息(u…

Matlab|计及光伏电站快速无功响应特性的分布式电源优化配置方法

目录 1 主要内容 目标函数 约束条件 程序亮点 2 部分代码 3 程序结果 4 下载链接 1 主要内容 该程序复现博士文章《互动环境下分布式电源与电动汽车充电站的优化配置方法研究》第二章《计及光伏电站快速无功响应特性的分布式电源优化配置方法》&#xff0c;本章选取了光…

ssrf漏洞之php-fpm未授权访问漏洞利用

目录 环境搭建 ​编辑漏洞点寻找 开始攻击 结果 环境搭建 在你的网站目录下创建一个新的php文件&#xff0c;内容如下 <?php highlight_file(__FILE__); $url $_GET[url]; $curl curl_init($url); curl_setopt($curl, CURLOPT_HEADER, 0); $responseText curl_exec…

闲鱼IP属地地址:去外地会自动变化吗?解析实时更新机制

在数字化时代&#xff0c;网络交易平台如闲鱼已成为我们日常生活中不可或缺的一部分。在进行二手交易时&#xff0c;了解对方的地理位置信息成为许多买家和卖家的关切点。那么&#xff0c;去外地闲鱼IP会变吗&#xff1f;闲鱼IP属地地址是实时更新吗&#xff1f;本文将深入探讨…

【代码随想录算法训练营第42期 第三十天 | LeetCode452. 用最少数量的箭引爆气球、435. 无重叠区间、763.划分字母区间】

代码随想录算法训练营第42期 第三十天 | LeetCode452. 用最少数量的箭引爆气球、435. 无重叠区间、763.划分字母区间 一、452. 用最少数量的箭引爆气球 解题代码C&#xff1a; class Solution { private:static bool cmp(const vector<int>& a, const vector<in…

SpringBoot多环境日志配置

SpringBoot 默认使用 LogBack 日志系统 默认情况下&#xff0c;SpringBoot项目的日志只会在控制台输入。 如果想查询历史日志则无法找到&#xff0c;我们需要一个日志系统来统一管理日志。 一般正式项目会有单独日志系统&#xff0c;将日志操作存入数据库。 第一种方式是 在 ap…

力扣hot100-动态规划

文章目录 概念动态规划基本思想常见步骤常用技巧常见问题类型 动态规划题目题目&#xff1a; 爬楼梯题解 概念 动态规划 动态规划&#xff08;Dynamic Programming&#xff0c;简称DP&#xff09;是一种解决问题的算法思想&#xff0c;通常用于优化问题。它的核心思想是将一个…

PTA L1-019 谁先倒

L1-019 谁先倒&#xff08;15分&#xff09; 划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为&#xff1a;每人口中喊出一个数字&#xff0c;同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和&#xff0c;谁就输了&#xff0c;输家罚…

sqli-labs靶场通关攻略(36-40关)

第36关&#xff08;宽字节注入&#xff08;Bypass MySQL Real Escape String&#xff09;&#xff09; 查数据库 ?id-1%df%27%20union%20select%202,database(),3%20-- 查表 ?id-1%df union select 1,group_concat(table_name),3 from information_schema.tables where tab…

图片生成box-shadow并下载

把图片生成由box-shadow拼接成的阴影组成的图片 html <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /><titl…

【焕新】同为科技(TOWE)23周年庆典

每年的8月23日&#xff0c;都是一个值得铭记、守护、欢庆的日子。这一天同为科技&#xff08;TOWE&#xff09;迎来公司成立23周年纪念日&#xff0c;是属于TOWE品牌向前、长远的里程碑。从2001到2024&#xff0c;从品牌与文化&#xff0c;从产品到服务。 同为科技&#xff08;…

Python自动化办公2.0 课程更新

之前的课程&#xff0c;包含了Python pandassklearn 数据分析&#xff0c;和Stremlit 可视化仪表盘的开发 和一系列自动化项目案例的开发&#xff0c;包括我们封装了ztl-uia 模块&#xff0c;可以同时自动化操控windows 软件和浏览器, 封装的模块&#xff0c;针对为付费学员使…

【AI模型:追求全能还是专精?】

&#x1f493; 博客主页&#xff1a;倔强的石头的CSDN主页 &#x1f4dd;Gitee主页&#xff1a;倔强的石头的gitee主页 ⏩ 文章专栏&#xff1a;《热点时事》 期待您的关注 目录 引言 ​编辑 一&#xff1a;AI模型的全面评估和比较 二&#xff1a;AI模型的专精化和可扩展性…

微软正式确认将在近期关闭经典Windows控制面板

微软在不断测试并为 Windows 添加新功能的同时&#xff0c;也在不断淘汰一些公司认为不再需要的功能。这些功能会被添加到Windows 过时功能的列表中&#xff0c;最近的一项功能是 Paint 3D&#xff0c;该公司宣布它很快就会被淘汰。 与微软似乎希望尽早取消的"3D 画图&quo…

uniapp video标签无法播放视频

当video标签路径含有中文以及特殊字符视频就会无法播放 解决方法使用encodeURIComponent对路径进行加密处理 videoSrc data.coursewareFile? ${appConfig.apiUrl encodeURIComponent(data.coursewareFile)}: "";最后效果

内衣洗衣机和手洗哪个干净?五款高评分内衣洗衣机实测分享!

在日常生活中&#xff0c;内衣洗衣机已成为现代家庭必备的重要家电之一。选择一款耐用、质量优秀的内衣洗衣机&#xff0c;不仅可以减少洗衣负担&#xff0c;还能提供高效的洗涤效果。然而&#xff0c;市场上众多内衣洗衣机品牌琳琅满目&#xff0c;让我们往往难以选择。那么&a…

增材制造(3D打印):为何备受制造业瞩目?

在科技浪潮的推动下&#xff0c;增材制造——即3D打印技术&#xff0c;正逐步成为制造业领域的璀璨新星&#xff0c;吸引了航空航天、汽车、家电、电子等众多行业的目光。那么&#xff0c;是什么让3D打印技术如此引人注目并广泛应用于制造领域&#xff1f;其背后的核心优势又是…

应用软件初始化的优缺点,读写ini,json,xml...

读写 INI 文件和读写 JSON 文件是两种常见的数据存储方式&#xff0c;它们各自有不同的优缺点&#xff0c;适用于不同的应用场景。以下是它们的一些比较&#xff1a; 读写 INI 文件 优点&#xff1a; 人类可读性&#xff1a;INI 文件格式简单&#xff0c;易于人类阅读和编辑…

2024前端面试题-js篇

1.js有哪些数据类型 基础数据类型&#xff1a;string,number,boolean&#xff0c;null&#xff0c;undefined&#xff0c;bigInt&#xff0c;symbol 引用数据类型&#xff1a;Object 2.js检测数据类型的方式 typeof&#xff1a;其中数组、对象、null都会被判断为object&…

Jupyter 的可视化 Debug

Jupyter 这种工具虽然有很好的交互性能&#xff0c;但其也明白&#xff0c;对于大型代码库&#xff0c;最好还是用传统的 IDE 比较靠谱。 因此为了弥补这一缺陷&#xff0c;Jupyter 项目在过去几年也希望通过 JupyterLab 来加强对大型代码库的处理过程。 然而&#xff0c;Jup…