​​​​ Python命令行工具 | 苏生不惑的博客

Python命令行工具

安装python3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
sudo yum install python34
$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo /usr/bin/python3.4 get-pip.py
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Collecting pip
Downloading http://mirrors.tencentyun.com/pypi/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 2.9MB/s
Collecting setuptools
Downloading http://mirrors.tencentyun.com/pypi/packages/d1/6a/4b2fcefd2ea0868810e92d519dacac1ddc64a2e53ba9e3422c3b62b378a6/setuptools-40.8.0-py2.py3-none-any.whl (575kB)
100% |████████████████████████████████| 583kB 2.7MB/s
Collecting wheel
[root@CentOS72 ~]# python3 -V
Python 3.4.3
[root@su ~]# pip3 -V
pip 19.0.3 from /usr/lib/python3.4/site-packages/pip (python 3.4)
https://blog.huzhifeng.com/2016/09/12/CentOS-7-Install-Python3-pip3/

显示Python包

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
//pip包网站 https://pypi.org/search/?q=cheat
//命令行安装目录 which httpstat /d/python/srcripts/
pip install https://github.com/mher/flower/zipball/master
$ pip list
Package Version
-------------------- ---------
aiohttp 3.4.4
alembic 1.0.0
amqp 2.3.2
asn1crypto 0.24.0
astral 1.6.1
async-timeout 3.0.0
attrs 18.2.0
Automat 0.7.0
Babel 2.6.0
bcrypt 3.1.4
billiard 3.5.0.4
bleach 2.1.4
boto3 1.4.7
botocore 1.7.48
cchardet 2.1.4
celery 4.2.1
certifi 2018.8.24
cffi 1.11.5
chardet 3.0.4
click 6.7
colorama 0.3.9
constantly 15.1.0
contextlib2 0.5.5
cryptography 2.3.1
defusedxml 0.5.0
docutils 0.14
et-xmlfile 1.0.1
Flask 0.12.4
Flask-AppBuilder 1.12.1
Flask-Babel 0.11.1
Flask-Caching 1.4.0
Flask-Compress 1.4.0
Flask-Login 0.4.1
Flask-Migrate 2.2.1
Flask-OpenID 1.2.5
Flask-Script 2.0.6
Flask-SQLAlchemy 2.3.2
Flask-Testing 0.7.1
Flask-WTF 0.14.2
flower 0.9.2
future 0.16.0
geographiclib 1.49
geopy 1.16.0
gunicorn 19.9.0
homeassistant 0.80.3
html5lib 1.0.1
humanize 0.5.1
hyperlink 18.0.0
idna 2.7
ijson 2.3
incremental 17.5.0
isodate 0.6.0
itsdangerous 0.24
jdcal 1.4
Jinja2 2.10
jmespath 0.9.3
jsonlines 1.2.0
jsonschema 2.6.0
kombu 4.2.1
linear-tsv 1.1.0
Mako 1.0.7
Markdown 3.0.1
MarkupSafe 1.0
multidict 4.4.2
mysqlclient 1.3.13
numpy 1.15.1
openpyxl 2.4.11
pandas 0.23.4
parsedatetime 2.4
pathlib2 2.3.2
pip 18.1
polyline 1.3.2
pure-sasl 0.5.1
pycparser 2.18
pydruid 0.4.5
PyHamcrest 1.9.0
PyHive 0.6.0
PyJWT 1.6.4
PyMySQL 0.9.2
python-dateutil 2.7.3
python-editor 1.0.3
python-geohash 0.8.5
python3-openid 3.1.0
pytz 2018.5
PyYAML 3.13
requests 2.19.1
rfc3986 1.1.0
s3transfer 0.1.13
selenium 3.14.0
setuptools 39.0.1
simplejson 3.16.0
six 1.11.0
SQLAlchemy 1.2.11
SQLAlchemy-Utils 0.33.3
sqlparse 0.2.4
superset 0.28.0
tableschema 1.2.5
tabulator 1.17.0
thrift 0.11.0
thrift-sasl 0.3.0
tornado 5.1
Twisted 18.9.0
unicodecsv 0.14.1
Unidecode 1.0.22
urllib3 1.23
vine 1.1.4
virtualenv 16.0.0
voluptuous 0.11.5
voluptuous-serialize 2.0.0
webencodings 0.5.1
Werkzeug 0.14.1
wheel 0.32.1
WTForms 2.2.1
xlrd 1.1.0
yarl 1.2.6
youtube-dl 2018.10.5
zope.interface 4.5.0

视频下载you-get

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
//https://github.com/soimort/you-get
$ you-get 'https://www.youtube.com/watch?v=jNQXAC9IVRw'
site: YouTube
title: Me at the zoo
stream:
- itag: 43
container: webm
quality: medium
size: 0.5 MiB (564215 bytes)
# download-with: you-get --itag=43 [URL]

Downloading Me at the zoo.webm ...
100% ( 0.5/ 0.5MB) ├██████████████████████████████████┤[1/1] 6 MB/s

Saving Me at the zoo.en.srt ... Done.
$ you-get https://stallman.org/rms.jpg
Site: stallman.org
Title: rms
Type: JPEG Image (image/jpeg)
Size: 0.06 MiB (66482 Bytes)

Downloading rms.jpg ...
100.0% ( 0.1/0.1 MB) ├████████████████████████████████████████┤[1/1] 127 kB/s

$ pip3 install -U lulu
$ lulu https://www.bilibili.com/video/av18295259/
site: Bilibili
title: 【中文八级】俄罗斯人的名字超乎你的想象
stream:
- format: flv720
container: flv
size: 175.4 MiB (183914793 bytes)
# download-with: lulu --format=flv720 [URL]

Downloading 【中文八级】俄罗斯人的名字超乎你的想象.flv ...
100% (175.4/175.4MB) ├████████████████████████████████████████┤[1/1] 3 MB/s

Downloading 【中文八级】俄罗斯人的名字超乎你的想象.cmt.xml ...

httpie

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
pip install --upgrade httpie
http httpie.org
HTTP/1.1 301 Moved Permanently
CF-RAY: 486fc237347a7948-LAX
Cache-Control: max-age=3600
Connection: keep-alive
Date: Mon, 10 Dec 2018 12:36:42 GMT
Expires: Mon, 10 Dec 2018 13:36:42 GMT
Location: https://httpie.org/
Server: cloudflare
Transfer-Encoding: chunked
Vary: Accept-Encoding
$ http PUT example.org X-API-Token:123 name=John
$ http DELETE example.org/todos/7
$docker pull kennethreitz/httpbin
$docker run -p 80:80 kennethreitz/httpbin
http tonydeng.github.io/blog/2015/07/10/httpie-howto/ User-Agent:Xmodlo/1.0 Referer:http://tonydeng.github.io
GET /blog/2015/07/10/httpie-howto/ HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: tonydeng.github.io
Referer: http://tonydeng.github.io
User-Agent: Xmodlo/1.0

http PUT tonydeng.github.io name='Tony Deng' email='tonydeng@email.com'
http -f POST tonydeng.github.io name='Tony Deng' email='tonydeng@email.com'
-f 选项使http命令序列化数据字段,并将Content-Type设置为application/x-www-form-urlencoded;charset=utf-8
当你不指定Content-Type发送请求参数时,它们就会自动序列化为JSON对象。
https://tonydeng.github.io/2015/07/10/httpie-howto/
http POST tonydeng.github.io name='Tony Deng' email='tonydeng@email.com'

POST / HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 52
Content-Type: application/json
Host: tonydeng.github.io
User-Agent: HTTPie/0.9.2
{
"email": "tonydeng@email.com",
"name": "Tony Deng"
}
http POST tonydeng.github.io < my_info.json
或:

echo '{"name": "Tony Deng","email": "tonydeng@email.com"}' | http POST tonydeng.github.io

清晰易读的 cURL 工具httpstat

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
pip install httpstat
wget https://raw.githubusercontent.com/reorx/httpstat/master/httpstat.py
go get github.com/davecheney/httpstat
https://learnku.com/articles/24048
$ httpstat httpbin.org
Connected to 54.152.127.232:80 from 10.235.51.43:55118

HTTP/1.1 200 OK
Connection: keep-alive
Server: gunicorn/19.9.0
Date: Mon, 10 Dec 2018 12:39:33 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 10122
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Via: 1.1 vegur

Body stored in: C:\Users\suping3\AppData\Local\Temp\tmppkgeite_

DNS Lookup TCP Connection Server Processing Content Transfer
[ 250ms | 234ms | 265ms | 15ms ]
| | | |
namelookup:250ms | | |
connect:484ms | |
starttransfer:749ms |
total:764ms
httpstat httpbin.org/post -X POST --data-urlencode "a=b" -v
https://wi1dcard.cn/posts/easier-curl-with-colors/

shadowsocks

1
2
3
4
5
pip install shadowsocks
ssserver -p 443 -k password -m rc4-md5
sudo ssserver -p 443 -k password -m rc4-md5 --user nobody -d start
sudo ssserver -d stop
less /var/log/shadowsocks.log

增强型语法高亮mycli

1
mycli -u用户名 -p密码

中文分词

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
from snownlp import SnowNLP

s = SnowNLP(u'这个东西真心很赞')

s.words # [u'这个', u'东西', u'真心',
# u'很', u'赞']

s.tags # [(u'这个', u'r'), (u'东西', u'n'),
# (u'真心', u'd'), (u'很', u'd'),
# (u'赞', u'Vg')]

s.sentiments # 0.9769663402895832 positive的概率

s.pinyin # [u'zhe', u'ge', u'dong', u'xi',
# u'zhen', u'xin', u'hen', u'zan']

s = SnowNLP(u'「繁體字」「繁體中文」的叫法在臺灣亦很常見。')

s.han # u'「繁体字」「繁体中文」的叫法
# 在台湾亦很常见。'

text = u'''
自然语言处理是计算机科学领域与人工智能领域中的一个重要方向。
它研究能实现人与计算机之间用自然语言进行有效通信的各种理论和方法。
自然语言处理是一门融语言学、计算机科学、数学于一体的科学。
因此,这一领域的研究将涉及自然语言,即人们日常使用的语言,
所以它与语言学的研究有着密切的联系,但又有重要的区别。
自然语言处理并不是一般地研究自然语言,
而在于研制能有效地实现自然语言通信的计算机系统,
特别是其中的软件系统。因而它是计算机科学的一部分。
'''

s = SnowNLP(text)

s.keywords(3) # [u'语言', u'自然', u'计算机']

s.summary(3) # [u'因而它是计算机科学的一部分',
# u'自然语言处理是一门融语言学、计算机科学、
# 数学于一体的科学',
# u'自然语言处理是计算机科学领域与人工智能
# 领域中的一个重要方向']
s.sentences

s = SnowNLP([[u'这篇', u'文章'],
[u'那篇', u'论文'],
[u'这个']])
s.tf
s.idf
s.sim([u'文章'])# [0.3756070762985226, 0, 0]

测试你的上下行网速

1
2
3
4
5
6
7
8
9
10
11
12
pip install speedtest-cli --upgrade
[root@VM_0_14_centos ~]# speedtest --share
Retrieving speedtest.net configuration...
Testing from Tencent cloud computing (118.24.158.116)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Beijing Broadband Network (Beijing) [1.69 km]: 36.987 ms
Testing download speed................................................................................
Download: 21.77 Mbit/s
Testing upload speed................................................................................................
Upload: 1.10 Mbit/s
Share results: http://www.speedtest.net/result/7842317337.png

cheat

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
pip install cheat
$ cheat curl
# Download a single file
curl http://path.to.the/file

# Download a file and specify a new filename
curl http://example.com/file.zip -o new_file.zip

# Download multiple files
curl -O URLOfFirstFile -O URLOfSecondFile

# Download all sequentially numbered files (1-24)
curl http://example.com/pic[1-24].jpg

# Download a file and pass HTTP Authentication
curl -u username:password URL

# Download a file with a Proxy
curl -x proxysever.server.com:PORT http://addressiwantto.access

# Download a file from FTP
curl -u username:password -O ftp://example.com/pub/file.zip

# Get an FTP directory listing
curl ftp://username:password@example.com

# Resume a previously failed download
curl -C - -o partial_file.zip http://example.com/file.zip

# Fetch only the HTTP headers from a response
curl -I http://example.com

# Fetch your external IP and network info as JSON
curl http://ifconfig.me/all/json

# Limit the rate of a download
curl --limit-rate 1000B -O http://path.to.the/file

# Get your global IP
curl httpbin.org/ip

# Get only the HTTP status code
curl -o /dev/null -w '%{http_code}\n' -s -I URL

curl cht.sh/curl
curl cht.sh/php/array_map

zhihu

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
$ pip install zhihuapi
import zhihuapi as api

with open('cookie') as f:
api.cookie(f.read())

data = api.user('zhihuadmin').profile()
print(data)
{
"url_token": "zhihuadmin",
"avatar_url": "https://pic3.zhimg.com/34bf96bf5584ac4b5264bd7ed4fdbc5a_is.jpg",
"avatar_url_template": "https://pic3.zhimg.com/34bf96bf5584ac4b5264bd7ed4fdbc5a_{size}.jpg",
"type": "people",
"name": "知乎小管家",
"headline": "欢迎反馈问题和建议!",
"is_org": false,
"url": "https://www.zhihu.com/people/zhihuadmin",
"badge": [
{
"type": "identity",
"description": "知乎官方帐号"
}
],
"user_type": "people",
"is_advertiser": false,
"id": "3d198a56310c02c4a83efb9f4a4c027e"
}

微信机器人

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
pip install -U wxpy -i "https://pypi.doubanio.com/simple/"
# 导入模块
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot()
# 搜索名称含有 "游否" 的男性深圳好友
my_friend = bot.friends().search('游否', sex=MALE, city="深圳")[0]
# 发送文本给好友
my_friend.send('Hello WeChat!')
# 发送图片
my_friend.send_image('my_picture.jpg')

pip install wechat_sender
from wxpy import *
from wechat_sender import *
bot = Bot()
listen(bot)
# 之后 wechat_sender 将持续运行等待接收外部消息
from wechat_sender import Sender
Sender().send('Hello From Wechat Sender')
# Hello From Wechat Sender 这条消息将通过 1 中登录微信的文件助手发送给你
pip install itchat
import itchat

itchat.auto_login()

itchat.send('Hello, filehelper', toUserName='filehelper')

数据可视化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Install superset
pip install superset

# Create an admin user (you will be prompted to set a username, first and last name before setting a password)
fabmanager create-admin --app superset

# Initialize the database
superset db upgrade

# Load some data to play with
superset load_examples

# Create default roles and permissions
superset init

# To start a development web server on port 8088, use -p to bind to another port
superset runserver -d

直接执行简单 Python 表达式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@VM_0_14_centos onpremise]# pip install pythonpy
Collecting pythonpy
Downloading http://mirrors.tencentyun.com/pypi/packages/01/ca/3b2c0fe88b4305dcaa2c575046781338add06e5670e3baf13a378e3acbd4/pythonpy-0.4.11.tar.gz
Installing collected packages: pythonpy
Running setup.py install for pythonpy ... done
Successfully installed pythonpy-0.4.11
You are using pip version 8.1.2, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@VM_0_14_centos onpremise]# py "248168/1024.0"
242.3515625
$ py "pandas.__version__"
0.16.2
$ py 'math.exp(1)'
2.71828182846

ppt 转 pdf 图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pip install PyWin32 Pillow reportlab 
git clone https://github.com/ernestyao/PPT2PDF.git
C:\PPT2PDF-master>python PPT2PDF.py test.pptx test.pdf
test
水印完成
准备生成C:\PPT2PDF-master\test_tank测试.pdf
C:\PPT2PDF-master\test_tank测试\幻灯片1.PNG
C:\PPT2PDF-master\test_tank测试\幻灯片2.PNG
C:\PPT2PDF-master\test_tank测试\幻灯片3.PNG
C:\PPT2PDF-master\test_tank测试\幻灯片4.PNG
C:\PPT2PDF-master\test_tank测试\幻灯片5.PNG
C:\PPT2PDF-master\test_tank测试\幻灯片6.PNG
C:\PPT2PDF-master\test_tank测试\幻灯片7.PNG
C:\PPT2PDF-master\test_tank测试\幻灯片8.PNG
完成PDF合成 http://blog.51yip.com/other/1934.html

二维码

1
2
3
4
5
6
7
8
# 逐一安装https://yfzhou.coding.me/2018/08/27/%E4%BD%BF%E7%94%A8-Python-%E7%94%9F%E6%88%90%E4%BA%8C%E7%BB%B4%E7%A0%81/
pip install pillow
pip install numpy
pip install imageio
pip install myqr
myqr https://github.com -p github.jpg -c

myqr https://github.com -p github.gif -c -con 1.5 -bri 1.6

数据分析

1
2
3
4
5
6
7
pip3 install pandas
python3 -m pip install --upgrade pip
python3 -m pip install jupyter
jupyter notebook
copy and paste one of these URLs:
http://localhost:8889/?token=3907c3efc88d7814cf8cfee262ad277d8cf8ae2c7cf97b8d
[I 13:51:10.834 NotebookApp] Creating new notebook in

i

uncurl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Python Requests转换助手有一个很棒的开源cURL http://curl.trillworks.com   https://github.com/NickCarneiro/curlconverter
pip install uncurl
[root@su ~]# uncurl "curl 'https://pypi.python.org/pypi/uncurl' -H 'Accept-Encoding: gzip,deflate,sdch'"
requests.get("https://pypi.python.org/pypi/uncurl",
headers={
"Accept-Encoding": "gzip,deflate,sdch"
},
cookies={},
)
echo "curl 'https://pypi.python.org/pypi/uncurl' -H 'Accept-Encoding: gzip,deflate,sdch'"|uncurl
import uncurl

>>> print(uncurl.parse("curl 'https://pypi.python.org/pypi/uncurl' -H 'Accept-Encoding: gzip,deflate,sdch'"))
requests.get("https://pypi.python.org/pypi/uncurl",
headers={
"Accept-Encoding": "gzip,deflate,sdch"
},
cookies={},
)

https://stackoverflow.com/questions/20461194/conversion-of-curl-to-python-requests
中文版stackoverflow http://landcareweb.com/questions/35099/jiang-curlzhuan-huan-wei-pythonqing-qiu

词云

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
$ wordcloud_cli --text mytext.txt --imagefile wordcloud.png
If you're dealing with PDF files, then pdftotext, included by default with many Linux distribution, comes in handy:


$ pdftotext mydocument.pdf - | wordcloud_cli --imagefile wordcloud.png
wordcloud_cli --text in.txt --imagefile out.png --mask in.png

text 是词云来源,mask 是背景框架 ,imagefile 输出的文件
wordcloud_cli.exe --text datas\data.json --fontfile assets\simkai.ttf --imagefile wordcloud.png
wordcloud_cli --help 查看所有支持的命令参数

usage: wordcloud_cli [-h] [--text file] [--regexp regexp] [--stopwords file]
[--imagefile file] [--fontfile path] [--mask file]
[--colormask file] [--contour_width width]
[--contour_color color] [--relative_scaling rs]
[--margin width] [--width width] [--height height]
[--color color] [--background color] [--no_collocations]
[--version]

A simple command line interface for wordcloud module.

optional arguments:
-h, --help show this help message and exit
--text file specify file of words to build the word cloud
(default: stdin)
--regexp regexp override the regular expression defining what
constitutes a word
--stopwords file specify file of stopwords (containing one word per
line) to remove from the given text after parsing
--imagefile file file the completed PNG image should be written to
(default: stdout)
--fontfile path path to font file you wish to use (default:
DroidSansMono)
--mask file mask to use for the image form
--colormask file color mask to use for image coloring
--contour_width width
if greater than 0, draw mask contour (default: 0)
--contour_color color
use given color as mask contour color - accepts any
value from PIL.ImageColor.getcolor
--relative_scaling rs
scaling of words by frequency (0 - 1)
--margin width spacing to leave around words
--width width define output image width
--height height define output image height
--color color use given color as coloring for the image - accepts
any value from PIL.ImageColor.getcolor
--background color use given color as background color for the image -
accepts any value from PIL.ImageColor.getcolor
--no_collocations do not add collocations (bigrams) to word cloud
(default: add unigrams and bigrams)
--version show program's version number and exit

命令行录制工具asciinema

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
pip3 install asciinema
https://asciinema.org/docs/installation
asciinema rec
录制完成 ctrl+d 或 exit 退出,可保存到本地(json 格式),也可上传到 https://asciinema.org ,设置为 public 后可分享观看,而且官方提供多种方式很容易嵌入到自己对网站使用。

https://asciinema.org/a/248319?t=5&speed=3&theme=solarized-dark
视频链接后加 .png 对应的是分享用的视频截图:https://asciinema.org/a/248319.png ,而视频链接后加 .js 是可以站外直接调用的播放链接:

<script src="https://asciinema.org/a/113463.js" id="asciicast-113463" async data-autoplay="true" data-size="big"></script>
https://learnku.com/articles/28920

[root@VM_0_14_centos ~]# asciinema rec
asciinema: recording asciicast to /tmp/tmpc_o6vho1-ascii.cast
asciinema: press <ctrl-d> or type "exit" when you're done
[root@VM_0_14_centos ~]# pip list
DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won't be maintained after March 2019 (cf PEP 429).
Package Version
---------------- -----------
argh 0.26.2
arrow 0.13.2
asciinema 2.0.2
asn1crypto 0.24.0
backports-abc 0.5
beautifulsoup4 4.7.1
binaryornot 0.4.4
blinker 1.4
brotlipy 0.7.0
certifi 2019.3.9
cffi 1.12.2
chardet 3.0.4
click 6.7
configparser 3.7.3
cookiecutter 1.6.0
cryptography 2.3.1
curlify 2.1.1
future 0.17.1
graphviz 0.8.4
greenlet 0.4.15
h11 0.7.0
h2 3.1.0
hiredis 1.0.0
hpack 3.0.0
hyperframe 5.2.0
idna 2.8
Jinja2 2.10.1
jinja2-time 0.2.0
kaitaistruct 0.8
ldap3 2.5.2
MarkupSafe 1.1.1
mitmproxy 4.0.4
msgpack 0.6.1
mxnet-cu90 1.4.0.post0
numpy 1.14.6
passlib 1.7.1
pathtools 0.1.2
peewee 3.9.2
pip 19.0.3
poyo 0.4.2
pyasn1 0.4.5
pycparser 2.19
pyOpenSSL 18.0.0
pyparsing 2.2.2
pyperclip 1.6.5
python-dateutil 2.8.0
pytz 2018.9
PyYAML 5.1
redis 3.2.1
requests 2.21.0
ruamel.yaml 0.15.91
setuptools 40.8.0
six 1.12.0
sortedcontainers 2.0.5
soupsieve 1.8
thrift 0.11.0
tornadis 0.8.1
tornado 5.1
torthrift 0.2.4
tzlocal 1.5.1
uncurl 0.0.8
urllib3 1.24.1
urwid 2.0.1
watchdog 0.9.0
wheel 0.33.1
when-changed 0.3.0
whichcraft 0.5.2
wsproto 0.11.0
xerox 0.4.1
you-get 0.4.1256
zdict 2.0.4
You are using pip version 19.0.3, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@VM_0_14_centos ~]# php -v
PHP 7.2.3 (cli) (built: Nov 28 2018 12:05:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

[root@VM_0_14_centos ~]# exit
asciinema: recording finished
asciinema: press <enter> to upload to asciinema.org, <ctrl-c> to save locally

View the recording at:

https://asciinema.org/a/IwvE2eERFLGCN1PeT0eIibwBG

This installation of asciinema recorder hasn't been linked to any asciinema.org
account. All unclaimed recordings (from unknown installations like this one)
are automatically archived 7 days after upload.

If you want to preserve all recordings made on this machine, connect this
installation with asciinema.org account by opening the following link:

https://asciinema.org/connect/01fb0f0e-c56a-450f-80ac-4020188dd957

Pyppeteer

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
pip3 install pyppeteer
http://quotes.toscrape.com/js/,这个页面是 JavaScript 渲染而成的,用基本的 requests 库请求得到的 HTML 结果里面是不包含页面中所见的条目内容的。
# 1 打开一个网页并做截图
# 首次运行示例时,pyppeteer会自动下载对应操作系统的chromium
import asyncio
from pyppeteer import launch

async def main():
browser = await launch()
page = await browser.newPage()
await page.goto('http://example.com')
await page.screenshot({'path': 'example.png'})
await browser.close()

asyncio.get_event_loop().run_until_complete(main())

# 2 在网页上执行一段脚本
import asyncio
from pyppeteer import launch

async def main():
browser = await launch()
page = await browser.newPage()
await page.goto('http://example.com')
await page.screenshot({'path': 'example.png'})

dimensions = await page.evaluate('''() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio,
}
}''')

print(dimensions)
# >>> {'width': 800, 'height': 600, 'deviceScaleFactor': 1}
await browser.close()

asyncio.get_event_loop().run_until_complete(main())
https://www.jianshu.com/p/611ed6b75d47

打开网站并截图
import asyncio
from pyppeteer import launch
async def main():
browser = await launch()
page = await browser.newPage()
await page.goto('https://zhangslob.github.io/')
await page.screenshot({'path': 'zhangslob.png'})
await browser.close()
asyncio.get_event_loop().run_until_complete(main())

第一次运行时需要下载Chromium,你可以提前在终端输入pyppeteer-install来下载
λ pyppeteer-install
[W:pyppeteer.chromium_downloader] start chromium download.
Download may take a few minutes.

命令行录屏工具

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 install TermRecord
它不会自动上传到网上,而是生成一个html文件,想要分享的话,你可以将其发送给好友。录制同样简单:

TermRecord -o ggg.html
同样使用exit或者Ctrl+D快捷键结束录制。要想查看录制结果,直接浏览器打开ggg.html就可以了。

pip3 install asciinema


asciinema rec
还是使用exit或者Ctrl+D快捷键结束录制。与showterm不同的是,它会在结束录制的时候提示,如果要上传的话,敲回车,这样就不至于把废品也上传了。上传之后,asciinema会给出一个网址,如:https://asciinema.org/a/44nu2i2ieywlmqq9wx5sk5k1e。要想嵌入到自己的网页上也没有问题:

<script type="text/javascript" src="https://asciinema.org/a/44nu2i2ieywlmqq9wx5sk5k1e.js" id="asciicast-44nu2i2ieywlmqq9wx5sk5k1e" async></script>
如果不想上传,可以用这条命令将其保存为一个json文件:

asciinema rec ggg.json
使用以下命令可以查看录制结果:

asciinema play ggg.json
甚至可以再次上传:

asciinema upload ggg.json
还能通过asciinema auth命令并在asciinema上注册账号来管理自己上传的文件,功能上确实是这几个工具中最强大的
http://qinghua.github.io/terminal-recorder/

音频拼接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 pip install sox
Collecting sox
Downloading https://files.pythonhosted.org/packages/60/a0/5bee540554af8376e0313e462629d95bf2f2bc3c8cb60697aa01254e6cf5/sox-1.3.7-py2.py3-none-any.whl
Installing collected packages: sox
Successfully installed sox-1.3.7
You are using pip version 19.0.3, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
import sox

cbn = sox.Combiner()
data = [filename1,filename2]
cbn.build(data, new_file, 'concatenate')
终端执行:https://learnku.com/articles/30609
sox --combine concatenate 1.wav 2.wav out.wav

命令行获取磁力工具

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
$ git clone https://github.com/cexll/cilimao-cli.git
$ cd cilimao-cli
$ pip install -r requires.txt
$ python setup.py install
磁力获取器命令行工具 pip install torrent-cli https://github.com/chenjiandongx/torrent-cli
λ cilimao-cli -h
命令行磁力猫查询
默认选择按视频排序,按下载热度排序

Usage:
cilimao [-p] <KEYWORD>
cilimao [-h,--help] 显示帮助菜单

Options:
-h,--help 显示帮助菜单
-p 页数(默认为0)

Example:
cilimao 复仇者联盟
cilimao -p 1 复仇者联盟

d:\code\cilimao-cli (master)
λ cilimao-cli 复仇者联盟
Crawling data for you.....
磁链标题: 复仇者联盟3
磁链地址: magnet:?xt=urn:btih:5A1F3081715D0F38AABD13D4499EF4153A56184E
文件数目: 1
文件大小: 2.9139890475198627GB
创建时间: 2018-05-17 18:33:25

获取ip和WiFi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ pip install ng
https://github.com/cls1991/ng
Get your ip address:

$ ng ip
`
local_ip:192.168.1.114
public_ip:49.4.160.250
`
Get wifi password:

$ ng wp
$ ng wp flyfish_5g
`
flyfish_5g:hitflyfish123456
`

5 秒抠图的 AI 神器

1
2
3
4
5
6
7
8
9
10
11
12
13
在网站上注册获取 API pip install removebg
from removebg import RemoveBg
rmbg = RemoveBg("WPZ2Q4fraseKfAN9PPxxxxxx", "error.log") # 引号内是你获取的API
rmbg.remove_background_from_img_file("C:/Users/sony/Desktop/1.jpg") #图片地址

from removebg import RemoveBg
import os

rmbg = RemoveBg("WPZ2Q4fraseKfAN9PPxxxxxx", "error.log")
path = '%s/picture'%os.getcwd() #图片放到程序的同级文件夹 picture 里面
for pic in os.listdir(path):
rmbg.remove_background_from_img_file("%s%s"%(path,pic))
https://github.com/brilam/remove-bg

摩尔斯密码

1
2
3
4
5
6
7
8
9
pip install morse-talk
import morse_talk as mtalk
content = 'i love you'
mo_content = mtalk.encode(content)
print mo_content
import morse_talk as mtalk
mo_content = '-.-- --- ..-'
content = mtalk.decode(mo_content)
print content

电影字幕下载神器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
pip install subliminal
subliminal download -l zh [电影名称]
from datetime import timedelta
https://github.com/Diaoul/subliminal
from babelfish import Language
from subliminal import download_best_subtitles, region, save_subtitles, scan_videos

# configure the cache
region.configure('dogpile.cache.dbm', arguments={'filename': 'cachefile.dbm'})

# scan for videos newer than 2 weeks and their existing subtitles in a folder
videos = scan_videos('/video/folder', age=timedelta(weeks=2))

# download best subtitles
subtitles = download_best_subtitles(videos, {Language('eng'), Language('fra')})

# save them to disk, next to the video
for v in videos:
save_subtitles(v, subtitles[v])

命令行工具 Speedtest-CLI 来测试你的上下行网速

一个命令行 Python 工具

2018python榜单

10 分钟速成 Python3

Windows 下有哪些替代 CMD 的命令行工具

有哪些命令行的软件堪称神器

优秀的命令行工具整理

10款Windows命令行工具

一些能够改你效率的工具

shell