JAVA程式設計師學Python一週開發的命令列小工具

語言: CN / TW / HK

theme: github highlight: a11y-dark


初學python, 開發一款程式設計師多功能小工具,取名x-tools,目前只包含資料轉換處理、http請求工具、檔案下載工具、密碼生成工具,後續會不斷完善,改進,歡迎大家一起交流學習。

安裝嚐鮮

!!!先確保你是mac系統或linux系統,並且已安裝了 python3、pip3、wget 工具,拷貝以下命令執行。 shell curl -fsSL http://raw.githubusercontent.com/telzhou618/x-tools/main/install.sh | bash 然後執行 x-tools,有如下顯示說明安裝成功。 ```shell

x-tools

Usage: x-tools [OPTIONS] COMMAND [ARGS]...

x-tools is a collection of tools developed in Python

Options: -h, --help Show this message and exit

Commands: data Data processor file File download password Password generate request Http request tools ```

開胃菜 - 先來幾個應用場景

10W+Execl 資料如何轉成批量SQL提交給運維匯入資料庫?

10w+條資料,csv格式 ,需要轉換成Inert SQL 語句,每1000條分隔為一條批量插入語句,可執行如下命令生成,最後將生成好語句檔案提交給運維執行即可,預設表名和csv檔名相同。 shell x-tools data --csv-to-sql ./t_user.csv -d 1000 -o ./t_user.sql

  • -csv-to-sql CSV檔案轉SQL語句
  • -d 多條資料合為一條批量SQL語句
  • -o 輸出到指定檔案,預設為當前目錄

如何生成一個安全可靠的密碼?

生成一個長度為16為的密碼 ```shell x-tools password -c 16

輸出:pzem8JEKr^bckGvN

```

如何優雅的發起 http請求 ?

GET請求: shell x-tools request http://www.httpbin.org/get ```json { "args": {}, "headers": { "Accept": "/", "Accept-Encoding": "gzip, deflate", "Host": "www.httpbin.org", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36", "X-Amzn-Trace-Id": "Root=1-61ee5456-001093d3593fd9f254deabaf" }, "origin": "101.68.65.50", "url": "http://www.httpbin.org/get"

POST請求:shell x-tools request http://www.httpbin.org/post -m post -j {\"p1\":\"v1\"} json { "args": {}, "data": "{\"p1\": \"v1\"}", "files": {}, "form": {}, "headers": { "Accept": "/", "Accept-Encoding": "gzip, deflate", "Content-Length": "12", "Content-Type": "application/json", "Host": "www.httpbin.org", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36", "X-Amzn-Trace-Id": "Root=1-61ee544f-5ab2eb2d2ea0359430d541fa" }, "json": { "p1": "v1" }, "origin": "101.68.78.162", "url": "http://www.httpbin.org/post" } ```

如何高效下載檔案(顯示進度條) ?

shell x-tools file -url http://vscode.cdn.azure.cn/stable/e5a624b788d92b8d34d1392e4c4d9789406efe8f/VSCodeUserSetup-x64-1.51.1.exe

image.png

更多功能和幫助

```shell

x-tools data 幫助文件

x-tools data --help

Usage: x-tools data [OPTIONS]

Data processor

Options: -csv-to-sql, --csv-to-sql TEXT Convert csv to sql -csv-to-json, --csv-to-json TEXT Convert csv to json -csv-to-jsonl, --csv-to-jsonlines TEXT Convert csv to jsonlines -csv-to-xls, --csv-to-xls TEXT Convert csv to xls -csv-to-xlsx, --csv-to-xlsx TEXT Convert csv to xlsx -d, --divide-limit INTEGER Limit number of batch sql generated -o, --out-file TEXT Output to file --help Show this message and exit. shell

x-tools password 幫助文件

x-tools password --help

Usage: x-tools password [OPTIONS]

Password generate

Options: -c, --count INTEGER Length of password, default is 16 chars -A, --upper-az BOOLEAN Contain characters[A~Z] -a, --letter-az BOOLEAN Contain characters[a~z] -n, --number BOOLEAN Contain characters[0~9] -s, --special BOOLEAN Contain characters[[email protected]#$%^&*] -all, --all-char BOOLEAN Contain all characters -o, --out-file TEXT Output to file -his, --history BOOLEAN History generated password --help Show this message and exit. shell

x-tools request 幫助文件

x-tools request --help

Usage: x-tools request [OPTIONS] URL

Http request tools

Example:

  x-tools request http://www.httpbin.org/get
  x-tools request http://www.httpbin.org/post -m post -j {\"p1\":\"v1\"}

Options: -m, --method [get|post|head|put|delete|options|patch] Request method -h, --headers TEXT Headers dict -p, --params TEXT Params dict -j, --json-params TEXT Json data dict -f, --files TEXT Upload files -fr, --format-result [text|json] Format return data --help Show this message and exit. shell

x-tools file 幫助文件

x-tools file --help

Usage: x-tools file [OPTIONS]

File download

Options: -url, --url TEXT file url [required] -name, --name TEXT Picture rename --help Show this message and exit. ```

專案地址

http://github.com/telzhou618/x-tools

歡迎star,歡迎初學python且希望能釋出一款自己的python程式的小夥伴一起交流學習。