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