毕业设计:python哔哩哔哩数据可视化分析系统 B站 bilibili数据 Flask框架 Echarts可视化(源码)✅
1、项目介绍
技术栈:
python语言、Flask框架、Echarts可视化、MySQL数据库、词云图、HTML
2、项目界面
(1)系统首页—数据概况
(2)B站评论弹幕分析
(3)B站作者分析
(4)B站视频可视化分析
(5)B站舆情分析
(6)标题词云图
(7)B站评论数据
(8)作者页面
(9)注册登录界面
(10)后台数据管理
3、项目说明
B站数据可视化分析系统
在当今信息爆炸的时代,数据的价值日益凸显。特别是在B站(哔哩哔哩)这样一个以视频内容为主的平台上,大量的用户评论、弹幕、视频信息等数据蕴含着丰富的价值。为了深入挖掘这些数据的潜在价值,我们开发了一款基于Python语言、Flask框架、Echarts可视化、MySQL数据库等技术的B站数据可视化分析系统。
该系统的主要功能包括B站评论弹幕分析、作者分析、视频可视化分析、舆情分析以及数据概况展示等。每个功能都旨在从不同角度揭示B站数据的规律和趋势,帮助用户更好地理解和利用这些数据。
首先,在系统首页上,用户可以直观地看到数据的整体概况。通过Echarts可视化图表,用户可以迅速了解B站的热门视频、热门作者、热门评论等信息,从而对B站的整体情况有一个全面的认识。
接下来,系统提供了B站评论弹幕分析功能。通过对用户评论和弹幕的抓取和分析,系统可以提取出关键词、情感倾向等信息,帮助用户了解用户的观点和情感。此外,系统还可以根据用户需求,对特定视频或作者的评论弹幕进行深度分析,揭示其特点和规律。
在作者分析方面,系统可以对B站的作者进行统计和分析。通过抓取和分析作者的视频数量、播放量、粉丝数等数据,系统可以评估作者的影响力和受欢迎程度。同时,系统还可以根据作者的发布频率、发布时间等信息,为作者提供个性化的优化建议。
视频可视化分析是系统的另一个重要功能。通过对视频数据的抓取和分析,系统可以提取出视频的播放量、点赞量、分享量等信息,并以可视化的形式展示给用户。用户可以通过这些图表了解视频的表现情况,并根据需要对视频进行优化和推广。
舆情分析功能是系统的一大亮点。通过对B站上的评论、弹幕等数据的抓取和分析,系统可以识别出热点话题、舆论趋势等信息,帮助用户了解用户对某个话题或事件的看法和态度。这对于企业、政府等组织来说具有重要的参考价值。
此外,系统还提供了标题词云图功能,通过对B站视频标题的抓取和分析,生成词云图展示给用户。用户可以通过词云图了解B站视频的热门话题和关键词分布情况。
最后,系统还具备注册登录界面和后台数据管理功能。用户可以通过注册登录界面进入系统,并在后台管理自己的数据和设置。同时,系统管理员也可以通过后台对系统进行管理和维护,确保系统的稳定运行和数据安全。
总之,B站数据可视化分析系统是一款功能强大、易于使用的数据分析工具。它利用先进的数据抓取和分析技术,深入挖掘B站数据的潜在价值,帮助用户更好地理解和利用这些数据。我们相信,该系统将成为B站数据分析和可视化领域的得力助手。
4、核心代码
import json
from flask import Flask,request,render_template,session,redirect
import re
import random
from utils.query import querys
from utils import getHomePageData
from utils import getPublicData
from utils import getUpInfoEcharts
from utils import getVideoCommentEcharts
from utils import getVideoListData
from utils import getSentimentData
from utils import themeModel
from snownlp import SnowNLP
from flask_sqlalchemy import SQLAlchemy
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
app = Flask(__name__)
# 配置MySQL数据库
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@localhost/bstation'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
app.secret_key = 'This is a app.secret_Key , You Know ?'
# 初始化Flask Admin
admin = Admin(app, name='后台管理')
@app.route('/')
def every():
return render_template('login.html')
@app.route("/login",methods=['GET','POST'])
def login():
if request.method == 'POST':
request.form = dict(request.form)
def filter_fns(item):
return request.form['email'] in item and request.form['password'] in item
users = querys('select * from user', [], 'select')
login_success = list(filter(filter_fns, users))
if not len(login_success):
return '账号或密码错误'
session['email'] = request.form['email']
session['userRole'] = login_success[0][-1]
return redirect('/home', 301)
else:
return render_template('./login.html')
@app.route("/registry",methods=['GET','POST'])
def registry():
if request.method == 'POST':
request.form = dict(request.form)
if request.form['password'] != request.form['passwordCheked']:
return '两次密码不符'
else:
def filter_fn(item):
return request.form['email'] in item
users = querys('select * from user', [], 'select')
filter_list = list(filter(filter_fn, users))
if len(filter_list):
return '该用户名已被注册'
else:
querys('insert into user(email,password) values(%s,%s)',
[request.form['email'], request.form['password']])
session['email'] = request.form['email']
return redirect('/login', 301)
else:
return render_template('./registry.html')
@app.route("/home")
def home():
email = session['email']
userRole = session['userRole']
xData,yData,y1Data= getHomePageData.getHomeBarData()
maxVideoLenName,maxVideoLen, userLen, maxLevelName, maxLevel,maxLikesName,maxLikes = getHomePageData.getPageData()
upInfoList,videoListCommentTop,videoListTop = getHomePageData.getHomeList()
upInfoAllList = getPublicData.getAllUpInfo()
return render_template('home.html',
email=email,xData=xData,
userRole=userRole,
yData=yData,
y1Data=y1Data,
maxVideoLenName=maxVideoLenName,
maxVideoLen=maxVideoLen,
userLen=userLen,
maxLevelName=maxLevelName,
maxLevel=maxLevel,
maxLikesName=maxLikesName,
maxLikes=maxLikes,
upInfoList=upInfoList[:5],
videoListCommentTop=videoListCommentTop,
videoListTop=videoListTop[:5],
upInfoAllList=upInfoAllList
)
@app.route("/tableData")
def tableData():
email = session['email']
commentList = getPublicData.getAllVideoCommentsList()[:50]
upInfoAllList = getPublicData.getAllUpInfo()
userRole = session['userRole']
return render_template('tableData.html',userRole=userRole,email=email,commentList=commentList,upInfoAllList=upInfoAllList)
@app.route("/userManager")
def userManager():
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
users = querys('select * from user where role = %s', ['admin'], 'select')
return render_template('userManager.html',userRole=userRole,email=email,upInfoAllList=upInfoAllList,users=users)
@app.route("/roleManager")
def roleManager():
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
users = querys('select * from user', [], 'select')
return render_template('roleManager.html',userRole=userRole,email=email,upInfoAllList=upInfoAllList,users=users)
@app.route("/editRoleManager/<int:userId>",methods=['GET','POST'])
def editRoleManager(userId):
userInfo = querys('''
select * from user where id = %s
''',[userId],'select')
if userInfo[0][-1] == 'user':
querys('''
UPDATE user
SET role=%s
where id = %s
''', ['admin', userId])
else:
querys('''
UPDATE user
SET role=%s
where id = %s
''', ['user', userId])
return redirect('/roleManager')
@app.route('/sentimentComment',methods=['GET','POST'])
def sentimentComment():
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
timeList = getSentimentData.getTimeList()
defaultTime = request.args.get('time') if request.args.get('time') else timeList[0]
x,y = getSentimentData.getSentimentCommentData(defaultTime)
dataList,content = themeModel.main(defaultTime)
sentimentRes = '积极' if SnowNLP(content).sentiments >= 0.5 else '消极'
resData =[]
for index,i in enumerate(x):
resData.append({
'name':i,
'value':y[index]
})
return render_template('sentimentComment.html',dataList=dataList,sentimentRes=sentimentRes,userRole=userRole,email=email,upInfoAllList=upInfoAllList,timeList=timeList,defaultTime=defaultTime,x=x,y=y,resData=resData)
@app.route("/addUserManager",methods=['GET','POST'])
def addUserManager():
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
if request.method == 'GET':
return render_template('addUserManager.html',userRole=userRole, email=email, upInfoAllList=upInfoAllList)
else:
newEmail = request.form.get('email')
newPassword = request.form.get('password')
querys('''
insert into user(email,password,role) values(%s,%s,%s)
''',[newEmail,newPassword,'admin'])
return redirect('/userManager')
@app.route("/deleteUserManager/<int:userId>",methods=['GET','POST'])
def deleteUserManager(userId):
querys('delete from user where id = %s',[userId])
return redirect('/userManager')
@app.route("/editUserManager/<int:userId>",methods=['GET','POST'])
def editUserManager(userId):
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
if request.method == 'GET':
userInfo = querys('''
select * from user where id = %s
''',[userId],'select')
return render_template('editUserManager.html',userRole=userRole, email=email, upInfoAllList=upInfoAllList,userInfo=userInfo[0],userId=userId)
else:
newEmail = request.form.get('email')
newPassword = request.form.get('password')
querys('''
UPDATE user
SET email=%s,
password=%s
where id = %s
''',[newEmail,newPassword,userId])
return redirect('/userManager')
@app.route('/upDetail')
def upDetail():
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
videoAllList = getPublicData.getAllVideoList()
videAllCommentVideo = getPublicData.getAllVideoCommentsList()
upId = upInfoAllList[0][0]
if request.args.get('upId'):upId = request.args.get('upId')
upInfo = []
for i in upInfoAllList:
if int(i[0]) == int(upId):
upInfo = i
videoAllList = list(filter(lambda x:int(x[-4]) == int(upInfo[1]),videoAllList))
videoId = videoAllList[0][0]
if request.args.get('videoId'):videoId = request.args.get('videoId')
videoInfo = []
for i in videoAllList:
if int(i[0]) == int(videoId):
videoInfo = i
videAllCommentVideo = list(filter(lambda x:int(x[1]) == int(videoInfo[2]),videAllCommentVideo))
commentInfo = videAllCommentVideo
return render_template('upDetail.html',
email=email,
upInfoAllList=upInfoAllList,
upInfo=upInfo,
videoAllList=videoAllList[:8],
videoInfo=videoInfo,
commentInfo=commentInfo[:5],
upId=upId,
userRole=userRole
)
@app.route('/upInfoEcharts')
def upInfoEcharts():
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
fensiData = getUpInfoEcharts.getFensiData()
levenData = getUpInfoEcharts.getLevenData()
xData,yData = getUpInfoEcharts.getVideLenData()
return render_template('upInfoEcharts.html',
email=email,
userRole=userRole,
upInfoAllList=upInfoAllList,
fensiData=fensiData,
levenData=levenData,
xData=xData,
yData=yData
)
@app.route('/videoCommentEcharts')
def videoCommentEcharts():
email = session['email']
timeList = getSentimentData.getTimeList()
defaultTime = request.args.get('time') if request.args.get('time') else timeList[0]
upInfoAllList = getPublicData.getAllUpInfo()
xData, yData, y1Data=getVideoCommentEcharts.getCommentLen(defaultTime)
x1Data,y2Data = getVideoCommentEcharts.getUserCommentLikeTopData(defaultTime)
sexData = getVideoCommentEcharts.getUserSexData(defaultTime)
levelData = getVideoCommentEcharts.getUserLevelData(defaultTime)
userRole = session['userRole']
return render_template('videoCommentEcharts.html',
email=email,
upInfoAllList=upInfoAllList,
xData=xData,
yData=yData,
y1Data=y1Data,
x1Data=x1Data,
userRole=userRole,
y2Data=y2Data,
sexData=sexData,
levelData=levelData,
defaultTime=defaultTime,
timeList=timeList
)
@app.route('/videoListEcharts')
def videoListEcharts():
email = session['email']
timeList = getSentimentData.getTimesList()
defaultTime = request.args.get('time') if request.args.get('time') else timeList[0]
upInfoAllList = getPublicData.getAllUpInfo()
xData,yData = getVideoListData.getVideoLenData(defaultTime)
x1Data,y1Data = getVideoListData.getSeeNumData(defaultTime)
userRole = session['userRole']
return render_template('videoListEcharts.html',
email=email,
upInfoAllList=upInfoAllList,
xData=xData,
userRole=userRole,
yData=yData,
x1Data=x1Data,
y1Data=y1Data,
timeList=timeList,
defaultTime=defaultTime
)
@app.route('/title_cloud')
def title_cloud():
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
return render_template('title_cloud.html',
email=email,
upInfoAllList=upInfoAllList,
userRole=userRole
)
@app.route('/comment_content_cloud')
def comment_content_cloud():
email = session['email']
userRole = session['userRole']
upInfoAllList = getPublicData.getAllUpInfo()
return render_template('comment_content_cloud.html',
email=email,userRole=userRole,
upInfoAllList=upInfoAllList
)
@app.route('/logOut')
def logOut():
session.clear()
return redirect('/login')
@app.before_request
def before_requre():
pat = re.compile(r'^/static')
if re.search(pat,request.path):
return
if request.path == "/login" :
return
if request.path == '/registry':
return
uname = session.get('email')
if uname:
return None
return redirect("/login")
if __name__ == '__main__':
app.run(port=5000)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
标签:return,request,upInfoAllList,session,可视化,userRole,毕业设计,哔哩,email
From: https://blog.csdn.net/biyesheji0006/article/details/143230749