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

本文主要是介绍分享一个基于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、微信小程序、爬虫、大数据、机器学习等,大家有这一块的问题可以一起交流!
💕💕学习资料、程序开发、技术解答、文档报告
💕💕如需要源码,可以扫取文章下方二维码联系咨询

这篇关于分享一个基于python新闻订阅与分享平台flask新闻发布系统(源码、调试、LW、开题、PPT)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1106457

相关文章

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

流媒体平台/视频监控/安防视频汇聚EasyCVR播放暂停后视频画面黑屏是什么原因?

视频智能分析/视频监控/安防监控综合管理系统EasyCVR视频汇聚融合平台,是TSINGSEE青犀视频垂直深耕音视频流媒体技术、AI智能技术领域的杰出成果。该平台以其强大的视频处理、汇聚与融合能力,在构建全栈视频监控系统中展现出了独特的优势。视频监控管理系统EasyCVR平台内置了强大的视频解码、转码、压缩等技术,能够处理多种视频流格式,并以多种格式(RTMP、RTSP、HTTP-FLV、WebS

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

基于人工智能的图像分类系统

目录 引言项目背景环境准备 硬件要求软件安装与配置系统设计 系统架构关键技术代码示例 数据预处理模型训练模型预测应用场景结论 1. 引言 图像分类是计算机视觉中的一个重要任务,目标是自动识别图像中的对象类别。通过卷积神经网络(CNN)等深度学习技术,我们可以构建高效的图像分类系统,广泛应用于自动驾驶、医疗影像诊断、监控分析等领域。本文将介绍如何构建一个基于人工智能的图像分类系统,包括环境

水位雨量在线监测系统概述及应用介绍

在当今社会,随着科技的飞速发展,各种智能监测系统已成为保障公共安全、促进资源管理和环境保护的重要工具。其中,水位雨量在线监测系统作为自然灾害预警、水资源管理及水利工程运行的关键技术,其重要性不言而喻。 一、水位雨量在线监测系统的基本原理 水位雨量在线监测系统主要由数据采集单元、数据传输网络、数据处理中心及用户终端四大部分构成,形成了一个完整的闭环系统。 数据采集单元:这是系统的“眼睛”,

python: 多模块(.py)中全局变量的导入

文章目录 global关键字可变类型和不可变类型数据的内存地址单模块(单个py文件)的全局变量示例总结 多模块(多个py文件)的全局变量from x import x导入全局变量示例 import x导入全局变量示例 总结 global关键字 global 的作用范围是模块(.py)级别: 当你在一个模块(文件)中使用 global 声明变量时,这个变量只在该模块的全局命名空

AI一键生成 PPT

AI一键生成 PPT 操作步骤 作为一名打工人,是不是经常需要制作各种PPT来分享我的生活和想法。但是,你们知道,有时候灵感来了,时间却不够用了!😩直到我发现了Kimi AI——一个能够自动生成PPT的神奇助手!🌟 什么是Kimi? 一款月之暗面科技有限公司开发的AI办公工具,帮助用户快速生成高质量的演示文稿。 无论你是职场人士、学生还是教师,Kimi都能够为你的办公文

高效+灵活,万博智云全球发布AWS无代理跨云容灾方案!

摘要 近日,万博智云推出了基于AWS的无代理跨云容灾解决方案,并与拉丁美洲,中东,亚洲的合作伙伴面向全球开展了联合发布。这一方案以AWS应用环境为基础,将HyperBDR平台的高效、灵活和成本效益优势与无代理功能相结合,为全球企业带来实现了更便捷、经济的数据保护。 一、全球联合发布 9月2日,万博智云CEO Michael Wong在线上平台发布AWS无代理跨云容灾解决方案的阐述视频,介绍了

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖