当前位置:   article > 正文

毕业设计:基于Python网易云音乐数据采集分析可视化系统+分析大屏 Flask框架 (附源码)建议收藏_2023网易云音乐+采集+可视化分析大屏+论文

2023网易云音乐+采集+可视化分析大屏+论文

[毕业设计]2023-2024年最新最全计算机专业毕设选题推荐汇总

感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人 。

在这里插入图片描述

1、摘 要

随着互联网技术的发展,音乐成为了人们生活中不可或缺的一部分,而网易云音乐作为国内最受欢迎的音乐平台之一,积累了大量的用户和歌单数据。针对这些数据,开发者们可以进行各种分析和挖掘,从而更好地理解用户需求和市场趋势。
本项目就是基于这个背景而设计的,旨在通过Python技术实现对网易云音乐热门歌单数据的采集、清洗、处理和可视化分析,并将结果保存到MySQL数据库中,最终通过Flask构建的数据服务接口实现数据的展示和管理。

2、开发环境

运行环境:推荐Python3.6及以上,推荐python3.7;
开发工具:PyChram(推荐);
操作系统:windows 10 8G内存以上(其他windows以及macOS支持,但不推荐);
浏览器:Firefox(推荐)、Google Chrome(推荐)、Edge;
数据库:MySQL8.0(推荐)及其他版本(支持,但容易异常尤其MySQL5.7(不含)以下版本);
数据库可视化工具:Navicat Premium 15(推荐)以及其他Navicat版本

3、项目简述:

后端:Flask、PyMySql、pandas、requests、bs4
前端:HTML、Jquery、Ajax、LayUI、Echarts
详细:
本项目主要采用了Python的request库、bs4库实现了网易云歌单数据的采集,然后使用pymysql将数据保存到MySQL数据库中。在数据清洗和处理方面,采用了Pandas等库来进行数据清洗和处理,从而得到干净、规范的数据。
在可视化分析方面,采用了Echarts技术实现歌单创建省份数量中国地图、最受欢迎的歌单类型TOP7,歌单分享量和评论数变化,歌单歌曲数量范围,最受欢迎的歌单TOP5、歌单收藏量变化、语种类型歌单播放量等多种分析图表,使得数据更加直观、易于理解。
在后台数据管理方面,采用了Layui技术实现了用户登陆注册、用户管理、公告管理以及歌单数据管理等多种功能,方便管理员对数据进行管理和维护。

4、功能介绍

本项目实现了以下主要功能:
网易云歌单数据的采集和处理,包括歌单基本信息、歌曲列表、评论数、分享量、创建时间等多种数据。
将数据保存到MySQL数据库中,以便后续进行数据分析和管理。
实现了数据可视化分析功能,包括歌单创建省份数量中国地图、最受欢迎的歌单类型TOP7,歌单分享量和评论数变化,歌单歌曲数量范围,最受欢迎的歌单TOP5、歌单收藏量变化、语种类型歌单播放量等多种分析图表。
实现了后台数据管理功能,包括用户登陆注册、用户管理、公告管理以及歌单数据管理等多种功能。

在这里插入图片描述

1、用户管理界面

在这里插入图片描述

2、歌曲管理界面

在这里插入图片描述

3、注册登录界面

在这里插入图片描述

4、后台首页
在这里插入图片描述

5、数据采集爬虫界面
在这里插入图片描述

5、部分代码

from flask import Flask, render_template, url_for
import json
import pandas as pd
import pymysql
import re
import decimal
from flask import Flask as _Flask, flash
from flask import request, session
from flask.json import JSONEncoder as _JSONEncoder, jsonify
import service.users_data as user_service
import service.notice_data as notice_data
import service.music_data as music_service
import datetime


class JSONEncoder(_JSONEncoder):
    def default(self, o):
        if isinstance(o, decimal.Decimal):
            return float(o)
        super(_JSONEncoder, self).default(o)


class Flask(_Flask):
    json_encoder = JSONEncoder


import os

app = Flask(__name__)
app.config['SESSION_TYPE'] = 'filesystem'
app.config['SECRET_KEY'] = os.urandom(24)

conn = pymysql.connect(
    host='127.0.0.1',
    user='root',
    password='123456',
    port=3306,  # 端口
    database='cloud_music',
    charset='utf8'
)

df = pd.read_sql('SELECT * FROM playlists,users WHERE users.id=playlists.id', con=conn)


# 登录
@app.route('/login', methods=['POST'])
def login():
    if request.method == 'POST':
        account = request.form.get('account')
        password = request.form.get('password')
        if not all([account, password]):
            flash('参数不完整')
            return "300"
        res = user_service.get_user(account, password)
        if res and res[0][0] > 0:
            session['is_login'] = True
            session['role'] = res[0][1]
            return "200"
        else:
            return "300"


# 登录页面跳转
@app.route('/admin')
def admin():
    if session.get("is_login"):
        if session.get('role') == 0:
            return render_template('admin.html')
        else:
            return render_template('admin1.html')
    else:
        return render_template('login.html')


@app.route('/logout')
def logout():
    try:
        session.pop("is_login")
        return render_template('login.html')
    except Exception:
        return render_template('login.html')


# 后台首页面跳转
@app.route('/html/welcome')
def welcome():
    return render_template('html/welcome.html')


# 后台注册跳转
@app.route('/html/reg')
def html_reg():
    return render_template('reg.html')


# -----------------用户管理模块START-----------------

# 用户管理页面
@app.route('/html/user')
def user_manager():
    return render_template('html/user.html')


# 获取用户数据分页
@app.route('/user/list', methods=["POST"])
def user_list():
    get_data = request.form.to_dict()
    page_size = get_data.get('page_size')
    page_no = get_data.get('page_no')
    param = get_data.get('param')
    data, count, page_list, max_page = user_service.get_user_list(int(page_size), int(page_no), param)
    return jsonify({"data": data, "count": count, "page_no": page_no, "page_list": page_list, "max_page": max_page})


# 注册用户数据
@app.route('/user/reg', methods=["POST"])
def user_reg():
    get_data = request.form.to_dict()
    name = str(get_data.get('username'))
    account = str(get_data.get('account'))
    password = str(get_data.get('password'))
    company = "平台注册"
    phone = " "
    mail = " "
    type = 1
    return user_service.add_user(name, account, password, company, phone, mail, type)


# 添加用户数据
@app.route('/user/add', methods=["POST"])
def user_add():
    get_data = request.form.to_dict()
    name = get_data.get('name')
    account = get_data.get('account')
    password = get_data.get('password')
    company = get_data.get('company')
    phone = get_data.get('phone')
    mail = get_data.get('mail')
    type = get_data.get('type')
    return user_service.add_user(name, account, password, company, phone, mail, type)


# 修改用户数据
@app.route('/user/edit', methods=["PUT"])
def user_edit():
    get_data = request.form.to_dict()
    id = get_data.get('id')
    name = get_data.get('name')
    password = get_data.get('password')
    company = get_data.get('company')
    phone = get_data.get('phone')
    mail = get_data.get('mail')
    type = get_data.get('type')
    user_service.edit_user(id, name, password, company, phone, mail, type)
    return '200'


# 删除用户数据
@app.route('/user/delete', methods=["DELETE"])
def user_delete():
    get_data = request.form.to_dict()
    id = get_data.get('id')
    user_service.del_user(id)
    return '200'


# -----------------用户管理模块END-----------------

# -----------------公告管理模块START-----------------

# 公告管理页面
@app.route('/html/notice')
def notice_manager():
    return render_template('html/notice.html')


# 获取最新公告
@app.route('/notice/new', methods=["POST"])
def notice_new():
    res = notice_data.get_notice()
    return jsonify({"title": res[1], "content": res[2], "user_name": res[3], "create_time": str(res[4])})


# 获取公告数据分页
@app.route('/notice/list', methods=["POST"])
def notice_list():
    get_data = request.form.to_dict()
    page_size = get_data.get('page_size')
    page_no = get_data.get('page_no')
    param = get_data.get('param')
    data, count, page_list, max_page = notice_data.get_notice_list(int(page_size), int(page_no), param)
    return jsonify({"data": data, "count": count, "page_no": page_no, "page_list": page_list, "max_page": max_page})


# 新增公告数据
@app.route('/notice/add', methods=["POST"])
def notice_add():
    get_data = request.form.to_dict()
    title = get_data.get('title')
    content = get_data.get('content')
    user_name = get_data.get('user_name')
    return notice_data.add_notice(title, content, user_name)


# 修改公告数据
@app.route('/notice/edit', methods=["PUT"])
def notice_edit():
    get_data = request.form.to_dict()
    id = get_data.get('id')
    title = get_data.get('title')
    content = get_data.get('content')
    user_name = get_data.get('user_name')
    notice_data.edit_notice(id, title, content, user_name)
    return '200'


# 删除公告数据
@app.route('/notice/delete', methods=["DELETE"])
def notice_delete():
    get_data = request.form.to_dict()
    id = get_data.get('id')
    notice_data.del_notice(id)
    return '200'


# -----------------公告管理模块END-----------------

# -----------------歌单管理模块START-----------------

# 歌单管理页面
@app.route('/html/music')
def music_manager():
    return render_template('html/music.html')


# 获取歌单数据分页
@app.route('/music/list', methods=["POST"])
def music_list():
    get_data = request.form.to_dict()
    page_size = get_data.get('page_size')
    page_no = get_data.get('page_no')
    param = get_data.get('param')
    data, count, page_list, max_page = music_service.get_musiclist_list(int(page_size), int(page_no), param)
    return jsonify({"data": data, "count": count, "page_no": page_no, "page_list": page_list, "max_page": max_page})


# 添加歌单数据
@app.route('/music/add', methods=["POST"])
def music_add():
    get_data = request.form.to_dict()
    name = get_data.get('name')
    type = get_data.get('type')
    tags = get_data.get('tags')
    create_time = get_data.get('create_time')
    tracks_num = get_data.get('tracks_num')
    play_count = get_data.get('play_count')
    subscribed_count = get_data.get('subscribed_count')
    share_count = get_data.get('share_count')
    comment_count = get_data.get('comment_count')
    nickname = get_data.get('nickname')
    gender = get_data.get('gender')
    province = get_data.get('province')
    return music_service.add_musiclist(name, type, tags, create_time, tracks_num, play_count, subscribed_count,
                                       share_count,
                                       comment_count, nickname, gender, province)


# 修改歌单数据
@app.route('/music/edit', methods=["PUT"])
def music_edit():
    get_data = request.form.to_dict()
    id = get_data.get('id')
    name = get_data.get('name')
    type = get_data.get('type')
    tags = get_data.get('tags')
    tracks_num = get_data.get('tracks_num')
    play_count = get_data.get('play_count')
    subscribed_count = get_data.get('subscribed_count')
    share_count = get_data.get('share_count')
    comment_count = get_data.get('comment_count')
    nickname = get_data.get('nickname')
    gender = get_data.get('gender')
    province = get_data.get('province')
    music_service.edit_musiclist(id, name, type, tags, tracks_num, play_count, subscribed_count, share_count,
                                 comment_count, nickname, gender, province);
    return '200'


# 删除歌单数据
@app.route('/music/delete', methods=["DELETE"])
def music_delete():
    get_data = request.form.to_dict()
    id = get_data.get('id')
    music_service.del_user(id)
    return '200'


# -----------------歌单但管理模块END-----------------

"""最受欢迎的歌单类型"""


@app.route('/get_hot_type')
def get_hot_type():
    hot_type_df = df[['type', 'play_count']].groupby(df['type']).sum().sort_values('play_count',
                                                                                   ascending=False).reset_index()
    hot_type_top7 = hot_type_df.head(7)
    playlist_type = hot_type_top7['type'].tolist()
    play_count = hot_type_top7['play_count'].tolist()

    return json.dumps({'playlist_type': playlist_type, 'play_count': play_count}, ensure_ascii=False)


"""最受欢迎的歌单"""


@app.route('/get_hot_playlist')
def get_hot_playlist():
    hot_playlist_df = df[['name', 'play_count']].sort_values('play_count', ascending=False).reset_index()
    hot_playlist_top5 = hot_playlist_df.head(5)
    playlist_name = hot_playlist_top5['name'].tolist()
    play_count = hot_playlist_top5['play_count'].tolist()
    return json.dumps({'playlist_name': playlist_name, 'play_count': play_count}, ensure_ascii=False)


"""歌单数据随月份变化"""


@app.route('/get_month_data')
def get_month_data():
    yearList = []

    # 获取当前日期和时间
    current_date = datetime.datetime.now()
    # 获取今年年份
    this_year = current_date.year
    # 获取去年年份
    last_year = this_year - 1
    for year in [last_year, this_year]:
        year = str(year)
        yearList.append({
            "year": year,
            "data": [
                df[df['create_time'].str[:4] == year].groupby(df['create_time'].str[5:7]).sum().reset_index()[
                    'share_count'].tolist(),
                df[df['create_time'].str[:4] == year].groupby(df['create_time'].str[5:7]).sum().reset_index()[
                    'comment_count'].tolist()
            ]
        })
    month = df[df['create_time'].str[:4] == str(this_year)].groupby(df['create_time'].str[5:7]).sum().reset_index()[
        'create_time'].tolist()
    yearData = {
        "yearData": yearList,
        "monthList": [str(int(x)) + '月' for x in month]
    }

    return json.dumps(yearData, ensure_ascii=False)


"""歌单数据随天数变化"""


@app.route('/get_day_data')
def get_day_data():
    non_vip_df = df[df['vip_type'] == '0'].groupby(df['create_time'].str[8:10]).sum().reset_index()[
        ['create_time', 'subscribed_count']]
    vip_df = \
        df[(df['vip_type'] == '10') | (df['vip_type'] == '11')].groupby(
            df['create_time'].str[8:10]).sum().reset_index()[
            ['create_time', 'subscribed_count']]
    vip_type_df = pd.merge(non_vip_df, vip_df, left_on='create_time', right_on='create_time', how='inner')

    sub_data = {
        "day": [str(int(x)) for x in vip_type_df["create_time"].tolist()],
        "vip": vip_type_df["subscribed_count_y"].tolist(),
        "nonvip": vip_type_df["subscribed_count_x"].tolist(),

    }

    return json.dumps(sub_data, ensure_ascii=False)


"""歌单歌曲数量分布"""


@app.route('/get_track_data')
def get_track_data():
    bins = [0, 50, 150, 500, 100000]
    cuts = pd.cut(df['tracks_num'], bins=bins, right=False, include_lowest=True)
    data_count = cuts.value_counts()
    data = dict(zip([str(x) for x in data_count.index.tolist()], data_count.tolist()))
    map_data = [{'name': name, 'value': value} for name, value in data.items()]
    track_value = {'t_v': map_data}

    return json.dumps(track_value, ensure_ascii=False)


"""语种类型歌单播放量"""


@app.route('/get_type_data')
def get_type_data():
    playlist_type_df = df[['type', 'play_count']].groupby(df['type']).sum()
    playlist_type_df = playlist_type_df.loc[['华语', '欧美', '日语', '韩语', '粤语'], :]
    data = dict(zip(playlist_type_df.index.tolist(), playlist_type_df['play_count'].tolist()))
    map_data = [{'name': name, 'value': value} for name, value in data.items()]
    type_sum = {'t_s': map_data}

    return json.dumps(type_sum, ensure_ascii=False)


def replace_str(x):
    rep_list = ['省', '市', '维吾尔', '自治区', '壮族', '回族', '维吾尔族', '特别行政区']
    for rep in rep_list:
        x = re.sub(rep, '', x)  # 利用正则表达式实现替换处理
    return x


def add_province(df_data, province):
    # 所有年份
    years = df_data['create_time'].drop_duplicates().tolist()
    for year in years:
        # 每年的省份
        new_province = df_data.loc[df_data['create_time'] == year, :]['province'].drop_duplicates().tolist()
        # 缺失的省份 = 所有省份 - 每年的省份
        rest_province = [x for x in province if x not in new_province]
        # 对缺失的省份生成一个DataFrame,填充0值,并与原DataFrame合并
        if len(rest_province):
            rest_df = pd.DataFrame([[year, x, 0] for x in rest_province], columns=df_data.columns)
            df_data = pd.concat([df_data, rest_df], ignore_index=True)

    return df_data


"""动态地图"""


@app.route('/get_map_data')
def get_map_data():
    time_df = df.groupby([df['create_time'].str[:4], df['province'].apply(replace_str)])
    time_df = time_df['play_count'].count().reset_index()
    re_time_df = time_df[time_df['province'] != '海外']
    province = re_time_df['province'].drop_duplicates().tolist()

    re_time_df2 = add_province(re_time_df, province)

    final_time_df = re_time_df2.sort_values(by=['create_time', 'province']).reset_index(drop=True)
    final_province = final_time_df['province'].drop_duplicates().tolist()
    final_year = final_time_df['create_time'].drop_duplicates().tolist()

    playlist_num = []
    for year in final_year:
        playlist_num.append(final_time_df.loc[final_time_df['create_time'] == year, 'play_count'].tolist())

    playlist_data = {"year": final_year, "province": final_province, "playlist_num": playlist_num}

    return json.dumps(playlist_data, ensure_ascii=False)


@app.route('/')
def index():
    gender_df = df[['gender']].groupby(df['gender']).count()
    gender_data = {'男': gender_df.loc['男', 'gender'], '女': gender_df.loc['女', 'gender']}

    return render_template('index.html', gender_data=gender_data)


if __name__ == "__main__":
    app.run()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470

源码获取:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/742309
推荐阅读
相关标签