关于curl:命令行搞一切之curl-的开心应用

2次阅读

共计 3891 个字符,预计需要花费 10 分钟才能阅读完成。

查看本人的外网 ip 地址

很多网站都提供这个性能,如:

curl -s ip.liquidweb.com
curl checkip.amazonaws.com
curl ifconfig.me
curl httpbin.org/ip

生成一个二维码

网址是 qrenco.de,即 QR encode,是不是很好记呢。

% curl qrenco.de/bixuebihui.com
█████████████████████████████
█████████████████████████████
████ ▄▄▄▄▄ █ ▄ █ █ ▄▄▄▄▄ ████
████ █   █ █ ▀▀  █ █   █ ████
████ █▄▄▄█ █▀▀██ █ █▄▄▄█ ████
████▄▄▄▄▄▄▄█▄▀ █▄█▄▄▄▄▄▄▄████
████  ▀▀ ▄▄▀▀ █▄█▀█▄▀▄▄ ▄████
████▀ █▄▀ ▄▀▄▀ █▀▀██ ██▄▀████
███████▄▄█▄▄ ▀▀▄██▀█ ▄█ ▄████
████ ▄▄▄▄▄ █▀▄▄█▀ █▀▄▄█ ▀████
████ █   █ █▄▀▀█▄ ██▀ ▀▀▀████
████ █▄▄▄█ █▀  ▀▀▄██ ████████
████▄▄▄▄▄▄▄█▄██▄█▄█▄████▄████
█████████████████████████████
█████████████████████████████

生成是显示在页面上看上去有点问题,命令行里还是能够扫到的。

查个字典

curl dict.org/d:entropy |less

curl dict.org/d:curl |less

抽奖时搞个偏心随机数

curl "https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new"

打小抄

curl http://cht.sh/java

会返回罕用的 java 的一些应用提醒。

curl http://cht.sh/js/promise

/*
 * understanding javascript promise object
 * 
 * Promise execution is asynchronous, which means that it's executed, but
 * the program won't wait until it's finished to continue with the rest
 * of the code.
 * 
 * Basically, your code is doing the following:
 * 
 *     1. Log 'Hi'
 *     2. Create a promise
 *     3. Execute the promise
 *     4. Log 'zami'
 *     5. Promise is resolved and logs 'There'.
 * If you want it to print 'Hi there, zami', you will have to
 */

myPromise.then(function (result) {
    // Resolve callback.
    console.log(result); 
    console.log('zami');
}, function (result) {
    // Reject callback.
    console.error(result);
});

/* [Alberto Rivera] [so/q/39458201] [cc by-sa 3.0] */

中文 OCR 辨认

这个网站有收费可用的 api:https://ocr.space/OCRAPI
通过 curl 简略调用能够辨认图片上的文字,能够指定语言。免费版每天可用 500 次,文件最大 1M。
反对 20 几种语言,包含中文。

调用示例:

curl -H "apikey:helloworld" --form "file=@screenshot.jpg" --form "language=eng" --form "isOverlayRequired=true" https://api.ocr.space/Parse/Image

应用前须要注册一个 apikey.

查看天气

$ curl wttr.in

会依据 ip 返回最近三天的天气

% curl wttr.in
Weather report: Beijing, China

       .-.      Light rain, mist
      ( ).    18 °C          
     (___(__)   ↑ 0 km/h‘‘‘‘5 km‘‘‘‘2.0 mm         
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Sun 19 Sep ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│  _`/"".-.     Light rain sho…│  _`/"".-.     Light rain sho…│      .-.      Moderate rain  │      .-.      Light rain     │
│   ,\_().   19 °C          │   ,\_().   19 °C          │     ().    17 °C          │     ().    16 °C          │
│    /(___(__)  ↑ 6-8 km/h     │    /(___(__)  ↑ 6-7 km/h     │    (___(__)   ← 10-14 km/h   │    (___(__)   ↓ 6-9 km/h     │
│‘‘‘‘10 km          │‘‘‘‘10 km          │   ‚‘‚‘‚‘‚‘7 km           │‘‘‘‘9 km           │
│‘‘‘‘0.2 mm | 74%   │‘‘‘‘0.4 mm | 97%   │   ‚’‚’‚’‚’2.5 mm | 95%   │‘‘‘‘1.9 mm | 94%   │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Mon 20 Sep ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│      .-.      Light rain     │               Cloudy         │    \  /       Partly cloudy  │               Overcast       │
│     ( ).    16 °C          │      .--.     17 °C          │  _ /"".-.     18 °C          │      .--.     17 °C          │
│    (___(__)   ↘ 20-34 km/h   │   .-().   ↘ 15-26 km/h   │    \_().   ↘ 5-9 km/h     │   .-( ).   → 4-8 km/h     │
│‘‘‘‘9 km           │  (___.__)__)  10 km          │    /(___(__)  10 km          │  (___.__)__)  10 km          │
│‘‘‘‘1.3 mm | 89%   │               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Tue 21 Sep ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│    \  /       Partly cloudy  │    \  /       Partly cloudy  │    \  /       Partly cloudy  │    \  /       Partly cloudy  │
│  _ /"".-.     21 °C          │  _ /"".-.     +24(25) °C     │  _ /"".-.     +23(25) °C     │  _ /"".-.     20 °C          │
│    \_().   → 15-20 km/h   │    \_().   ↘ 23-27 km/h   │    \_().   ↓ 6-10 km/h    │    \_().   → 4-7 km/h     │
│    /(___(__)  10 km          │    /(___(__)  10 km          │    /(___(__)  10 km          │    /(___(__)  10 km          │
│               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘

Follow @igor_chubin for wttr.in updates

你在北京,想看看上海的天气,也很简略

正文完
 0