Python 笔记

pip

1
2
3
# mac 安装 pip3
curl https://bootstrap.pypa.io/get-pip.py | python3
pip3 --version
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 查看已经安装软件列表
pip freeze
pip list

# 查看当前配置
python -m site

pip install xlrd              # 最新版本
pip install xlrd==1.0.4       # 指定版本
pip install 'xlrd>=1.0.4'     # 最小版本

# 更新包
pip install --upgrade xlrd

# 卸载包
pip uninstall xlrd

pip search xlrd

# 生成 requirements.txt
pip freeze > requirements.txt

# 安装 requirements.txt
pip install -r requirements.txt

中国镜像

临时

1
pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com xlrd

永久

C:\Users\LJW\pip\pip.ini

1
2
3
4
5
[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
disable-pip-version-check = true
timeout = 120

/root/.pip/pip.conf

腾讯云内网镜像

1
2
3
[global]
index-url = http://mirrors.tencentyun.com/pypi/simple
trusted-host = mirrors.tencentyun.com

腾讯云外网镜像

1
2
3
[global]
index-url = https://mirrors.cloud.tencent.com/pypi/simple
trusted-host = mirrors.cloud.tencent.com

sandman2

sandman2, Automatically generate a RESTful API service for your legacy database. No code required!

1
2
3
4
5
6
7
pip install sandman2

cd python-sandman2
sandman2ctl "sqlite+pysqlite:///sandman2.db" -p 9080

http://localhost:5000/team
http://localhost:5000/admin/team/

命令列表

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
(base) D:\WWW\python\python-automagica>sandman2ctl -h
usage: sandman2ctl [-h] [-d] [-p PORT] [-l] [-r] [-s SCHEMA] URI

Auto-generate a RESTful API service from an existing database.

positional arguments:
  URI                   Database URI in the format
                        postgresql+psycopg2://user:password@host/database

optional arguments:
  -h, --help            show this help message and exit
  -d, --debug           Turn on debug logging
  -p PORT, --port PORT  Port for service to listen on
  -l, --local-only      Only provide service on localhost (will not be
                        accessible from other machines)
  -r, --read-only       Make all database resources read-only (i.e. only the
                        HTTP GET method is supported)
  -s SCHEMA, --schema SCHEMA
                        Use this named schema instead of default

常驻进程

1
2
3
4
5
6
7
# gosuv
# Anaconda3 安装目录 D:\Link\Anaconda3
# sandman2.db 位于目录 D:\WWW\python\python-sandman2
# 端口号自定义 9080

call D:\Link\Anaconda3\Scripts\activate.bat D:\Link\Anaconda3 && cd /d D:\WWW\python\python-sandman2 && sandman2ctl sqlite+pysqlite:///sandman2.db -p 9080
C:\Windows\System32

端口占用规范

1
2
3
4
5
# Linux
lsof -i

# Windows
netstat -anop tcp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
9000 html
9010 webpack
9020 webpack
9030 node
9040 node
9050 node
9060 php
9070 java
9080 python
9090 go

django

django, The web framework for perfectionists with deadlines.

1
2
3
4
5
6
conda install django
django-admin startproject django-api
cd django-api

python manage.py runserver 9081
http://localhost:9081

命令列表

 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
(base) D:\WWW\python\django_api>python manage.py -h

Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[auth]
    changepassword
    createsuperuser

[contenttypes]
    remove_stale_contenttypes

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver

[sessions]
    clearsessions

[staticfiles]
    collectstatic
    findstatic
    runserver

常驻进程

1
2
3
4
5
6
# gosuv
# Anaconda3 安装目录 D:\Link\Anaconda3
# django 项目目录位于 D:\WWW\python\django_api
# 端口号自定义 9080

call D:\Link\Anaconda3\Scripts\activate.bat D:\Link\Anaconda3 && cd /d D:\WWW\python\django_api && python manage.py runserver 9081

automagica

automagica, an open source Smart Robotic Process Automation (SRPA) platform.

1
pip install automagica --upgrade

命令列表

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
(base) D:\WWW\python\python-automagica>automagica -h
usage: automagica.exe [-h] [--login LOGIN] [--logout] [--daemon]
                      [--foreground] [--config] [-f FILE] [-s SCRIPT]
                      [-p PARAMETERS] [--ignore-warnings] [--verbose]

Automagica Robot v1.0.11

optional arguments:
  -h, --help            show this help message and exit
  --login LOGIN         Log in with access key
  --logout              Log out
  --daemon              Run robot as a daemon
  --foreground          Keep process in the foreground
  --config              Alternate path to config
  -f FILE, --file FILE  Path to script file
  -s SCRIPT, --script SCRIPT
                        Script string for the Automagica robot (if no --file
                        not specified)
  -p PARAMETERS, --parameters PARAMETERS
                        Parameters string for the Automagica Bot
  --ignore-warnings     Python warnings will not end up in stderr
  --verbose             Verbose logging

MECARD 二维码名片

Google Chart 提供了很多在线生成统计图的 API,例如饼图、柱状图等等,

请求的API地址及参数

API地址: https://chart.googleapis.com/chart

请求参数:

1
2
3
4
5
cht=qr 生成图片的格式为二维码格式
chs=widthxheight 生成图片的大小。例如要生成300x300的图片,参数值为chs=300x300
chl=data 二维码中包含的内容,内容必须使用UTF-8格式编码
choe=output_encoding 非必要参数。输出的内容编码格式,默认为UTF-8
chld=L|M|Q|H 非必要参数,生成的二维码的容错率

链接示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
https://chart.googleapis.com/chart
?cht=qr
&chld=H
&chs=400x400
&chl=MECARD:
N:赖经纬;
NICKNAME:Jim;
TEL:13412345678;
EMAIL:laijingwei1993@163.com;
ADR:江西赣州;
URL:https://laijw.com;
BDAY:1993-06-14;
NOTE:很好的一个家伙;

正常版

1
https://chart.googleapis.com/chart?cht=qr&chld=H&chs=400x400&chl=MECARD:N:赖经纬;NICKNAME:Jim;TEL:13412345678;EMAIL:laijingwei1993@163.com;ADR:江西赣州;URL:https://laijw.com;BDAY:1993-08-01;NOTE:挺不错的一个小伙子;

精简版

1
https://chart.googleapis.com/chart?cht=qr&chld=H&chs=300x300&chl=MECARD:N:赖经纬;TEL:13412345678;EMAIL:laijingwei1993@163.com;URL:https://laijw.com;

Chrome 显示明文密码

浏览器中有个非常好用的功能就是记住网站的账号和密码,下次访问网站时会自动填充非常方便

也可以通过直接打开浏览器自带的开发者工具,改下代码就可以。的确如此,但小此方法过于繁琐

1
javascript:"use strict";!function(){var e,t;e=document.getElementsByTagName("input");for(var a=0;a<e.length;a++)if(t=e[a],"password"==t.type.toLowerCase())try{t.type="text"}catch(e){var r,n;r=document.createElement("input"),n=t.attributes;for(var o=0;o<n.length;o++){var i,c,d;i=n[o],c=i.nodeName,d=i.nodeValue,"type"!=c.toLowerCase()&&"height"!=c&&"width"!=c&!!d&&(r[c]=d)}t.parentNode.replaceChild(r,t)}}();