bat*_*__s 5 windows batch weather curl cmd.exe
如何使用 获得天气结果cURL
,为其分配一个变量以供以后使用?就像是:
# This doesn't work and is only a reference for what I want:
set mytemperature= curl www.yahoo.com/(mycity)/weather.temperature
echo %mytemperature%
Run Code Online (Sandbox Code Playgroud)
要将描述和温度保存在.bat
文件中的变量中,还要从输出中删除字符??
(十六进制:)并取回度数符号 [ ]:[0xB0 and 0xC2
wttr.in
London: +13??C
º
@echo off
cd /d "%~dp0" && setlocal EnableDelayedExpansion
>nul chcp 437 && set /p "_city=Please, enter some location, city, an attraction: "
for /f "delims= " %%d in ('forFiles /p "." /m "%~nx0" /c "cmd /c echo(0xF8"')do set "_o=%%~d"
for /f tokens^=* %%i in ('^<con: curl https://wttr.in/%_city: =+%^?format^=%%l:+%%t\n -s
')do for /f %%T in ('^<con: cmd /u /c "echo\%%~i"^<nul^|find/v "%_o%"^|findstr /v ^,"
')do set "_dt=!_dt!%%~T"
set "_description_temperature=!_dt::=: !" && call echo\!_description_temperature:+=!!_o!C
timeout -1 & endlocal & goto :eof
Run Code Online (Sandbox Code Playgroud)
输出: London: +13°C
rem :: char hex code
rem :: ? == 0xB0 // removed in loop
rem :: ? == 0xC2 // removed in loop
rem :: ° == 0xF8 // set _description_temperature=!_dt::=: !!_o!
Run Code Online (Sandbox Code Playgroud)
老的:
(curl http://wttr.in/riodejaneiro -UserAgent "curl" ).Content
Run Code Online (Sandbox Code Playgroud) 或者 powershell -nop -c "(curl http://wttr.in/riodejaneiro -UserAgent "curl" ).Content"
Run Code Online (Sandbox Code Playgroud) curl http://wttr.in
],否则将假定您当前的位置显示数据:
@echo off && title <nul && title %~nx0 && mode 128,45
powershell -nop -c "(curl http://wttr.in/riodejaneiro -UserAgent "curl" ).Content"
Run Code Online (Sandbox Code Playgroud)
set _temp=cmd /a /v /c "curl wttr.in/RioDeJaneiro?format=^%t --silent"
%_temp%
Run Code Online (Sandbox Code Playgroud)
定义输出:
$ curl wttr.in/London?format=%l:+%t\n
London: +13°C
Run Code Online (Sandbox Code Playgroud)
c Weather condition,
C Weather condition textual name,
h Humidity,
t Temperature (Actual),
f Temperature (Feels Like),
w Wind,
l Location,
m Moonphase ,
M Moonday,
p precipitation (mm),
P pressure (hPa),
D Dawn*,
S Sunrise*,
z Zenith*,
s Sunset*,
d Dusk*.
(*times are shown in the local timezone)
Run Code Online (Sandbox Code Playgroud)
$ curl wttr.in/London?format=3
London: ?? +7?C
$ curl wttr.in/London?format="%l:+%c+%t\n"
London: ?? +7?C
Run Code Online (Sandbox Code Playgroud)
curl wttr.in/*
Run Code Online (Sandbox Code Playgroud)
将温度转化为变量:
@echo off
chcp 1252 > nul
::Put your city here:
set City=Rio de Janeiro
set City_=%City: =-%
for /f "Delims=" %%a in ('curl --silent wttr.in/%City_%?format^=%%t') do set "CTemperature=%%a"
set CTemperature=%CTemperature:+=%
set CTemperature=%CTemperature:~0,-3%
echo The current temperature in %City% is %CTemperature% º Celcios
echo.
pause
Run Code Online (Sandbox Code Playgroud)
将温度和天气描述转化为变量:
@echo off
chcp 1252 > nul
::Put your city here:
set City=Rio de Janeiro
set City_=%City: =-%
for /f "Delims=" %%a in ('curl --silent wttr.in/%City_%?format^=%%t') do set "CTemperature=%%a"
set CTemperature=%CTemperature:+=%
set CTemperature=%CTemperature:~0,-3%
for /f "skip=1 tokens=4*" %%a in ('curl --silent wttr.in/%City_%?0') do set "Description=%%a %%b"& goto :Next
:Next
echo.
echo The current temperature in %City% is %CTemperature% º Celcios "%Description%"
echo.
pause
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
680 次 |
最近记录: |