『楼 主』:
[原创+讨论]智能获取72小时天气预报
功能:根据IP判断地理位置,然后获取相应地区72小时内的天气预报。
其中有一个很明显的不足之处:
控制变量输出的时候,排版真不好搞``虽然效果很好,但有点勉强,望牛人指点给出更好的方案或者算法。
关键效果截图:
也可从这里下载: http://kumho.lin.googlepages.com/WeatherCapturer.bat
@echo off
if "%1"=="" goto :FullScreen
::还原显示模式
REG ADD HKEY_CURRENT_USER\Console /v FullScreen /t REG_DWORD /d %1 /f>nul
cls
title 智能获取72小时天气预报 --- 腾讯版 Code By Kumho Lin
color 0b
setlocal EnableDelayedExpansion
set "a=FileName: WeatherCapturer.exe"
set "b=FileVersion: 1.0.0.1"
set "c=Function: Get the weather information in 72 hours according to your location"
set "d=Author: Kumho Lin"
set "e=QQ: 240460440"
set "f=E-Mail: kumho.lin@gmail.com"
set "g=HomePage: http://kumho.lin.googlepages.com"
set "h=Are you sure you wanna run this batch program right now [Y/N]?"
for %%i in (a b c d e f g h) do (
set/p=<nul
for /l %%a in (0,1,100) do (
if not "!%%i:~%%a,1!"=="" (
if "%%a"=="100" echo.&echo;
set/p=!%%i:~%%a,1!<nul
for /l %%p in (1,1,200) do ver>nul
)
)
echo.
)
set /p choice=
if /i "%choice%"=="y" (goto Begin) else goto Out
:Out
exit
:Begin
cls
ping -n 2 127.1 >nul 2>nul
:: →→→→→→→→→→→→→ Loading The Program ←←←←←←←←←←
(set,=Loading the program, please wait a minute&for /l %%c In (0,1,42)do @call set/p=%%,:~%%c,1%%<nul)&set,=&ping -n 2 127.1>nul&set/p="."<nul&ping -n 2 127.1>nul&set/p="."<nul&ping -n 2 127.1>nul&set/P="."<nul&ping -n 3 127.1>nul
cls
set num=20
set a==
set n=1
for /l %%i in (1,1,80) do (
cls
set /a num+=1
echo !num!%%
echo !a!
set a=!a!=
set /a n+=1
for /l %%j in (1,1,150) do ver>nul
)
ping -n 1 127.1 >nul 2>nul
echo Loading Complete
ping -n 2 127.1 >nul 2>nul
endlocal
cls
:: →→→→→→→→→→→→→ Loading The Program ←←←←←←←←←←
:: ************************** 判断是否联网 *****************************
setlocal EnableDelayedExpansion
set a=The program is detecting your system, please wait a minute...
for %%i in (a) do (
set/p=<nul
for /l %%a in (0,1,100) do (
if not "!%%i:~%%a,1!"=="" (
if %%a==100 echo.&echo;
set/p=!%%i:~%%a,1!<nul
for /l %%i in (1,1,100) do ver>nul
)
)
echo.
)
endlocal
ping -n 2 127.1>nul 2>nul
cls
ping -n 2 www.ip138.com >nul 2>nul
if %errorlevel% equ 0 (goto ready) else goto problem
:problem
setlocal DisableDelayedExpansion
set "A= Your computer is not connecting to the Internet !!!"
set "B="
for /l %%j in (1,1,10) do (
set/p=%A%<nul
set/p=%B%<nul
for /l %%i in (1,1,500) do ver>nul
set/p= <nul
for /l %%i in (1,1,500) do ver>nul
set/p=%B%<nul
ping -n 1 127.1 >nul 2>nul
)
endlocal
MSG * /time:3 ***** 您必须连接到互联网才能使用该功能 *****
goto quit
:ready
echo The batch program is connecting to the Internet, please wait a few seconds...
ping -n 4 127.1>nul 2>nul
cls
:: ==================== 获取IP、地理位置及ISP脚本开始 ===================
echo Set oDOM = WScript.GetObject(WScript.Arguments(0))>%TEMP%\Text.vbs
echo Do Until oDOM.readyState = "complete">>%TEMP%\Text.vbs
echo WScript.sleep 200>>%TEMP%\Text.vbs
echo Loop>>%TEMP%\Text.vbs
echo WScript.echo oDOM.documentElement.outerText>>%TEMP%\Text.vbs
echo Set oDOM=nothing>>%TEMP%\Text.vbs
cscript //NoLogo /E:vbscript %TEMP%\Text.vbs http://www.ip138.com | find /i "您的IP地址是" 2>nul>%TEMP%\location.txt
for /f "tokens=2 delims=[]" %%i in (%TEMP%\location.txt) do set true_ip=%%i
for /f "tokens=2,3 delims= " %%k in (%TEMP%\location.txt) do (
set your_location=%%k
set true_isp=%%l
)
echo %your_location:~3,-1%>%TEMP%\your_location.txt
for /f "tokens=1,2 delims=省" %%p in (%TEMP%\your_location.txt) do (
set true_province=%%p
set true_city=%%q
)
:: ==================== 获取IP、地理位置及ISP脚本结束 ===================
:: ************************* 获取气温信息脚本开始 ***********************
cscript //nologo /e:vbscript %TEMP%\Text.vbs http://kumho.lin.googlepages.com/city.txt|find /v /i "javascript" 2>nul>%TEMP%\cityInfo.txt
for /f "tokens=1 delims=/" %%i in ('find /i "%true_city%" %TEMP%\cityInfo.txt') do set cityCode=%%i
set "cityAddress=http://weather.news.qq.com/inc/07_dc%cityCode%.htm"
echo Set oDOM = WScript.GetObject(WScript.Arguments(0))>%TEMP%\HTML.vbs
echo Do Until oDOM.readyState = "complete">>%TEMP%\HTML.vbs
echo WScript.sleep 200>>%TEMP%\HTML.vbs
echo Loop>>%TEMP%\HTML.vbs
echo WScript.echo oDOM.documentElement.outerHTML>>%TEMP%\HTML.vbs
echo Set oDOM=nothing>>%TEMP%\HTML.vbs
cscript //nologo /e:vbscript %TEMP%\HTML.vbs %cityAddress% 2>nul>%TEMP%\source.txt
:: ******** 获取气温信息代码 ********
Setlocal EnableDelayedExpansion
set a=1
for /f "tokens=4 delims= " %%i in ('type %TEMP%\source.txt^|find /i "#eef3f8"') do (
set var=%%i
set string=!var:~10!
set num=!string:^<BR^>=#!
for /f "tokens=1,2 delims=#" %%a in ("!num!") do (
set tq!a!=%%a
set wd!a!=%%b
)
set /a a+=1
)
endlocal
:: ******** 获取日期信息代码 ********
Setlocal EnableDelayedExpansion
set b=1
for /f "tokens=4 delims=, " %%i in ('type %TEMP%\source.txt^|find /i "#eeeeee"') do (
set time1=%%i
set time2=!time1:^>=#!
set time3=!time2:^<=#!
for /f "tokens=2 delims=#" %%a in ("!time3!") do set rq!b!=%%a
set /a b+=1
)
endlocal
:: ************************* 获取气温信息脚本结束 ***********************
:: /*-*-*-*-*-*-*-*-*-*-* 获取操作系统版本信息开始 *-*-*-*-*-*-*-*-*-*-*/
Systeminfo 2>nul >%TEMP%\systeminfo.txt
type %TEMP%\systeminfo.txt | Find /I /V "BIOS 版本:" >%TEMP%\eol.txt
For /F "tokens=3*" %%I in ('type %TEMP%\systeminfo.txt ^| Find /I "OS 名称:"') Do Set os_name=%%I %%J
For /F "tokens=3,4,5,6 delims= " %%i in ('type %TEMP%\eol.txt ^| Find /I "OS 版本:"') Do Set os_ver=%%i %%j %%k %%l
Set os_name_ver=%os_name% %os_ver%
:: /*-*-*-*-*-*-*-*-*-*-* 获取操作系统版本信息结束 *-*-*-*-*-*-*-*-*-*-*/
:: ------------------------- 变量显示排版代码开始 -----------------------
:: --------变量注释开始--------
:: OS Version: %os_name_ver%
:: IP Address: %true_ip%
:: 省份: %true_province%
:: 城市: %true_city%
:: ISP: %true_isp%
:: 日期: %rq1% %rq2% %rq3%
:: 温度: %wd1% %wd2% %wd3%
:: 天气: %tq1% %tq2% %tq3%
:: --------变量注释结束--------
setlocal EnableDelayedExpansion
set a=┌───────────────────────────────────┐
set b=│ %os_name_ver% │
set c=├───────────────────────────────────┤
set d=│ %true_province%%true_city%地区72小时天气预报 │
set e=├───────────┬───────────┬───────────┤
set f=│ %rq1% │ %rq2% │ %rq3% │
set g=├───────────┼───────────┼───────────┤
set h=│ %wd1% │ %wd1% │ %wd1% │
set i=├───────────┼───────────┼───────────┤
set j=│ %tq1% │ %tq2% │ %tq3% │
set k=└───────────┴───────────┴───────────┘
for %%i in (a b c d e f g h i j k) do (
set/p= <nul
for /l %%a in (0,1,100) do (
if not "!%%i:~%%a,1!"=="" (
if %%a==100 echo.&echo;
set/p=!%%i:~%%a,1!<nul
for /l %%i in (1,1,70) do ver>nul
)
)
echo.
)
endlocal
echo.
echo.
del %TEMP%\location.txt %TEMP%\cityInfo.txt %TEMP%\your_location.txt %TEMP%\source.txt %TEMP%\systeminfo.txt %TEMP%\eol.txt %TEMP%\Text.vbs %TEMP%\HTML.vbs >nul 2>nul
ping -n 6 >nul 2>nul
:: ━━━━━━━━━━━━━━━ 尾部声明开始 ━━━━━━━━━━━━━
setlocal DisableDelayedExpansion
set "P= 各段代码的功能均有注释,不足之处,请多多指教 !!!"
set "K="
for /l %%j in (1,1,10) do (
set/p=%P%<nul
set/p=%K%<nul
for /l %%i in (1,1,250) do ver>nul
set/p= <nul
for /l %%i in (1,1,300) do ver>nul
set/p=%K%<nul
ping -n 1 127.1 >nul 2>nul
)
echo.
(Set,= http://kumho.lin.googlepages.com&For,/L,%%g,in,(0,1,85)Do,@Call,Set/P=%%,:~%%g,1%%<Nul&Ping/n 1 127.1>Nul)&Set,=&Ping -n 4 127.1>Nul
:: ━━━━━━━━━━━━━━━ 尾部声明结束 ━━━━━━━━━━━━━
:: ------------------------- 变量显示排版代码结束 -----------------------
:quit
exit
:FullScreen
::查询显示模式
Set ShowMode=0
for /f "delims=" %%i in ('REG QUERY HKEY_CURRENT_USER\Console /v "FullScreen"') do set ShowMode=%%i
Set ShowMode=%ShowMode:~-1%
::设置显示模式为全屏
REG ADD HKEY_CURRENT_USER\Console /v FullScreen /t REG_DWORD /d 1 /f>nul
::全屏启动当前脚本
start "" %0 %ShowMode% --------------------------------------------------------------------------------------------------
更新:
1. 在slore的帮助下实现了全屏幕效果
缺陷:
修改注册表再传参数调用批处理自身的这种方法用在我这个批处理上,似乎不那么顺利,有些变量获取不到,绝非网速慢的原因,因为我以默认窗口大小运行该批处理,然后按ALT+ENTER,也是全屏幕,能正常获取到相应的变量,这些变量是需要联网才能获取到的。
运行我更新后的代码效果如下:
┌───────────────────────────────────┐
│ Microsoft Windows XP Professional 5.1.2600 Service Pack 2 │
├───────────────────────────────────┤
│ 广东广州地区72小时天气预报 │
├───────────┬───────────┬───────────┤
│ │ │ │
├───────────┼───────────┼───────────┤
│ │ │ │
├───────────┼───────────┼───────────┤
│ │ │ │
└───────────┴───────────┴───────────┘ [ Last edited by dosmania on 2007-9-23 at 07:38 PM ]
此帖被 +39 点积分 点击查看详情 评分人:【 knoppix7 】 | 分数: +4 | 时间:2007-9-21 18:07 | 评分人:【 scriptor 】 | 分数: +2 | 时间:2007-9-22 01:10 | 评分人:【 lxmxn 】 | 分数: +12 | 时间:2007-9-22 20:58 | 评分人:【 bjsh 】 | 分数: +12 | 时间:2007-9-22 23:50 | 评分人:【 HAT 】 | 分数: +8 | 时间:2007-9-23 12:42 | 评分人:【 xiaohacker 】 | 分数: +1 | 时间:2007-12-10 20:16 |
|
|