This is the 23rd day of my participation in the First Challenge 2022

Learn about cloud server development with my boss (if you are reading this series for the first time, it is highly recommended to learn the following articles) :

Pilot: Have a server, I unexpectedly so cool?

Alternative project: write a resume page in 10 lines of code!

How to apply for a free SSL certificate for a domain name

A pagoda in Linux, a real pagoda! Detailed tutorial

Finally, a website that everyone can visit

How to send alarm notifications to spikes using Python?

How to send tweets automatically in Python?

Finally, I “built” a job that could program anywhere, anytime

How to build a nail robot that can automatically reply

Use Python to make a fund query robot, can also expand!

Hello, I am my old cousin

I used Python to make a fund query robot, but also can expand! , the required Python environment is version 3.7 or later, and the first time you have installed Python on Linux (previously Python3.6.8), note.

1. Download the Python source code from the official website

It is recommended to download the file locally (faster download speed) and then upload the file to the server through the pagoda.

To download the python version, go to the local browser services website and click on it.

https://www.python.org/downloads/source/
Copy the code

Notice that the stable version is on the left and the pre-released version is on the right. I selected Python3.7.9 here. ClickDownload XZ compressed source tarball.

We uploaded the Python source package to the specified folder on the server through the pagoda (I created a soft folder under the root/Project folder). After uploading the package, we can directly right-click in the pagoda and decompress it.

If you’re not sure how to install and use the pagoda panel, check out this article: “Pagodas” in Linux, Real Pagodas! Detailed tutorial

2. Install Python

Then we can continue to use the pagoda, click the pagoda panel terminal, enter the following commands.

  • CD Go to the Python source directory
  • ./configure Sets the installation location
  • Make compiles the source code to generate an executable file
  • Make install installs the compiled executable file into the installation directory set through configure

The final installation directory I set here is /usr/local/python3.7

cd/ root/soft/Python - 3.7.9. / configure -- prefix = / usr /local/ python3.7 make make installCopy the code

After the installation is successful, the installation directory will also be printed, indicating that the directory has not been added to the environment variable. We can add it or directly configure the soft link.

  • Method 1: Configure environment variables

First use of the nano open configuration file ~ /. Bashrc, add a line at the end the export PATH = “/ usr/local/python3.7 / bin: $PATH”, save the exit, finally under the running configuration file.

nano ~/.bashrc
After adding environment variables, run the configuration file
source ~/.bashrc
Copy the code

But even then, you have to set up soft links or use Python 3.7 to access Python programs.

  • Method 2: Set a soft link

The ln directive is used to link the PYTHon3.7 executable directly to PYTHon3 in /usr/bin and PIp3.7 to PIp3 in /usr/bin, so we can use python3 pip3 directly to version 3.7.

  • Ln -s indicates soft link
  • Ln -f forcibly links a directory. If the link has been linked to another directory before, delete the previous link and create a new link
ln -sf /usr/local/python3.7/bin/python3.7 /usr/bin/python3
ln -sf /usr/local/ python3.7 / bin/pip3.7 / usr/bin/pip3Copy the code

With that set up, we can just type python3 –version to see if the link is successful.

3. Simple use

  • Setting the Mirror Source

Create a. PIP folder to store PIP configuration files.

mkdir .pip && cd .pip
Copy the code

We’re still using the Nano command to edit the file,

nano pip.conf 
Copy the code

Copy the following contents into it, then press CTRL + O to save the file and CTRL + X to exit edit mode.


[global]
index-url = https://mirrors.aliyun.com/pypi/simple

[install]
trusted-host = mirrors.aliyun.com
Copy the code

Besides Ali Cloud image, you can also choose other image sources,

https://pypi.mirrors.ustc.edu.cn/simple douban http://pypi.douban.com/simple China university of science and technology of tsinghua university https://pypi.tuna.tsinghua.edu.cn/simple http://pypi.mirrors.ustc.edu.cn/simple university of science and technology of ChinaCopy the code
  • Installing third-party Packages

In order to create and manage the virtual environment, install the request library for crawling data and install the library for manipulating data.

pip3 install pipenv rquests pandas 
Copy the code
  • Write a small program: generate random passwords

Select a random number of characters of a specified length from numbers, upper and lower case letters, and special characters to form a string.

1 > character set

We can type it ourselves, or we can use an off-the-shelf package, such as String, which is a built-in Python package that allows us to get various characters very quickly.

import string
string.printable
Copy the code

2> Random function

Random is also a built-in package of Python, including randint, random, randrange, choice, choices, and other functions.

import random
random.choices('abc', k=2)
Copy the code

3> Random password generation program
import string
import random
while True:
    try:
        password_len = int(input('Please enter password length (number only) :'))
        password = ' '.join(random.choices(string.printable.strip(), k=password_len))
        print(F 'Your new password is:{password}, please keep ~ ')
    except Exception as e:
        print(F '[error] check if there is any input error.{e}')
    print('type 0 if you want to end!! * * * ')
    print('*** Enter to continue generating a new password ***')
    flag = input('Continue to generate a new password:')
    if flag == '0':
        break
    print('* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *')

Copy the code

Later there is time, I will optimize, hey hey hey ~

Persistence and hard work: results.

So see you next time, I love the cat love technology, more love si si’s old cousin Da Da ଘ(˙꒳˙)ଓ Di Di