1. The sequence

I wrote a python program to automatically generate career data for players, and I was very pleased with the response. I’ve had people ask me how to do it, how to learn Python, and advice on integrating it into the Web.

In fact, I also thought about integrating into the Web at the beginning, but due to time constraints, I just did a simple, unexpectedly caused everyone’s attention and suggestions. So this time I did an upgrade and integrated it into the Web!

Let’s look at the effect first, for example in local:

http://127.0.0.1:5800/retire/player?retire= Jordan & game = 1

http://127.0.0.1:5800/retire/player?retire= Bryant & game = 1

2. Configure the environment

. Language: Python3. Editor: Pycharn. Web framework: Flask. Data visualization: Pyecharts

There is a requirements. TXT file in the project home directory, which contains the dependency packages required for the project

pip install -r requirements.txt
Copy the code

Dependencies are installed automatically

3. Upgrade functions

Now the following functions have been added after the upgrade:

3.1 Integrate crawler into Web, and obtain all players under the team by inputting the team name in the browser

http://127.0.0.1:5800/nba/team?name= the raptors

3.2 Active ServiceAll the playersCareer data curves are also includedRegular season and playoffsdata

Kawhi Leonard’s regular season and playoff stats

http://127.0.0.1:5800/nba/player?game=0&player=kawhileonard-3568.html&color=yellow

When game=0, get regular season data, and game=1 get playoff data

The public account only supports uploading the following 2M GIF, GIF big and not support, GIF small and not clear… So a lot of times after recording the video clip into GIF to spend more than 20 minutes of time, very painful… Which friend has a good method, please contact me!

3.3 At the same time, support retired star data, such as the oldest hooligan in basketballJordan

3.4 Support to change the background color, at the same time support picture download

For example magic Johnson’s data, add color parameter at request

http://127.0.0.1:5800/retire/player?retire= the magician & game = 1 & color = yellow

Set the background color according to the color you send. At the same time, there is a download button in the upper left corner. Click to download. Isn’t it powerful!

4. Code explanation

4.1 part Flask

Request address: There are three request addresses, the code is in urls.py, which can be changed to suit your preferences

The address of the player is/NBA /team/, the career data of the active player is/NBA /player/, the data of the retired player is /retire/player/

Request parameter: Forms.py where the code resides

The code for what parameters to pass is up here. Color is optional!

Run the project: There is a run.py file in the home directory of the project, just run it!

4.2 Crawler

The previous program was to capture the data above the tiger, tiger has a bug: each player has a summary of 2017 data (not clear what it is), now fixed. Also, tiger does not support historical player data query, so a new website has been added with the following code:

Mainly involves HTML extraction technology, the previous article has been introduced, unspecified said.

4.3 Data visualization

This part is about integrating Pyecharts into Flask, some of the integrated files in Templates are default files, and the new part is about sending Ajax requests to generate player curves. There is not much to say because my previous articles have introduced the use of Pyecharts.

Python Programming and Practice

Source code address: github.com/GoJerry/nba…