China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-30 20:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original + Discussion] Smartly Obtain 72-Hour Weather Forecast View 2,761 Replies 25
Original Poster Posted 2007-09-21 15:53 ·  中国 广东 广州 天河区 电信
初级用户
★★
Credits 172
Posts 54
Joined 2007-01-02 10:38
19-year member
UID 75260
Gender Male
Status Offline
Function: Determine the geographical location based on the IP, then obtain the 72-hour weather forecast for the corresponding area.

One very obvious shortcoming is:
It's really hard to handle the layout when controlling the variable output``Although the effect is good, it's a bit forced. I hope experts can give better solutions or algorithms.

Key effect screenshots:



It can also be downloaded from here: http://kumho.lin.googlepages.com/WeatherCapturer.bat


@echo off
if "%1"=="" goto :FullScreen
::Restore display mode
REG ADD HKEY_CURRENT_USER\Console /v FullScreen /t REG_DWORD /d %1 /f>nul

cls
title Intelligent Acquisition of 72-Hour Weather Forecast --- Tencent Version 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 ?"
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 ←←←←←←←←←←


:: ************************** Determine whether connected to the Internet *****************************

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 ***** You must be connected to the Internet to use this function *****
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

:: ==================== Start of script to obtain IP, geographical location and 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 "Your IP address is" 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
)

:: ==================== End of script to obtain IP, geographical location and ISP ===================

:: ************************* Start of script to obtain temperature information ***********************

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

:: ******** Code to obtain temperature information ********

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
:: ******** Code to obtain date information ********
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
:: ************************* End of script to obtain temperature information ***********************

:: /*-*-*-*-*-*-*-*-*-*-* Start of script to obtain operating system version information *-*-*-*-*-*-*-*-*-*-*/

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%

:: /*-*-*-*-*-*-*-*-*-*-* End of script to obtain operating system version information *-*-*-*-*-*-*-*-*-*-*/

:: ------------------------- Start of variable display layout code -----------------------

:: -------- Start of variable comments --------
:: OS Version: %os_name_ver%
:: IP Address: %true_ip%
:: Province: %true_province%
:: City: %true_city%
:: ISP: %true_isp%
:: Date: %rq1% %rq2% %rq3%
:: Temperature: %wd1% %wd2% %wd3%
:: Weather: %tq1% %tq2% %tq3%
:: -------- End of variable comments --------

setlocal EnableDelayedExpansion
set a=┌───────────────────────────────────┐
set b=│ %os_name_ver% │
set c=├───────────────────────────────────┤
set d=│ %true_province%%true_city% Area 72-Hour Weather Forecast │
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

:: ━━━━━━━━━━━━━━━ Start of tail statement ━━━━━━━━━━━━━
setlocal DisableDelayedExpansion
set "P= Each segment of code has comments. For any shortcomings, please give more advice !!!"
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
:: ━━━━━━━━━━━━━━━ End of tail statement ━━━━━━━━━━━━━
:: ------------------------- End of variable display layout code -----------------------
:quit
exit

:FullScreen
::Query display mode

Set ShowMode=0
for /f "delims=" %%i in ('REG QUERY HKEY_CURRENT_USER\Console /v "FullScreen"') do set ShowMode=%%i
Set ShowMode=%ShowMode:~-1%

::Set display mode to full screen
REG ADD HKEY_CURRENT_USER\Console /v FullScreen /t REG_DWORD /d 1 /f>nul

::Start current script in full screen
start "" %0 %ShowMode%


--------------------------------------------------------------------------------------------------
Update:
1. With the help of slore, the full-screen effect is realized

Defect:
The method of modifying the registry and then passing parameters to call the batch script itself seems not so smooth for my batch script. Some variables cannot be obtained. It is definitely not because of slow network speed, because I run the batch script in the default window size, and then press ALT+ENTER, which is also full screen, and can normally obtain the corresponding variables. These variables need to be obtained online.

The effect of running my updated code is as follows:


┌───────────────────────────────────┐
│ Microsoft Windows XP Professional 5.1.2600 Service Pack 2 │
├───────────────────────────────────┤
│ Guangdong Guangzhou Area 72-Hour Weather Forecast │
├───────────┬───────────┬───────────┤
│ │ │ │
├───────────┼───────────┼───────────┤
│ │ │ │
├───────────┼───────────┼───────────┤
│ │ │ │
└───────────┴───────────┴───────────┘


[ Last edited by dosmania on 2007-9-23 at 07:38 PM ]
Recent Ratings for This Post ( 6 in total) Click for details
RaterScoreTime
knoppix7 +4 2007-09-21 18:07
scriptor +2 2007-09-22 01:10
lxmxn +12 2007-09-22 20:58
bjsh +12 2007-09-22 23:50
HAT +8 2007-09-23 12:42
xiaohacker +1 2007-12-10 20:16
Floor 2 Posted 2007-09-21 17:29
新手上路
Credits 11
Posts 5
Joined 2007-06-08 14:48
19-year member
UID 90667
Gender Male
Status Offline
Wow, come down and learn something
Floor 3 Posted 2007-09-22 01:09 ·  中国 北京 中国科学院研究生院玉泉四公寓
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Great! Give it a thumbs up!
Floor 4 Posted 2007-09-22 20:57 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
It's a very good program, let's give a thumbs up first.

As for the final table display, there are indeed some small issues. It can be achieved by using variable interception plus tag calls. The function of the tag is to import the characters to be displayed into a temporary file temp, and then use %~z of for to get the file size, and determine the length of the intercepted characters according to this size.

I wrote a similar table output before, but after searching for a long time without result, here I just provide an idea.
Floor 5 Posted 2007-09-23 00:36 ·  中国 广东 广州 电信
初级用户
★★
Credits 172
Posts 54
Joined 2007-01-02 10:38
19-year member
UID 75260
Gender Male
Status Offline
I seem to have seen before that the moderator named namejm posted a thread about variable formatting, and I forgot where it was.

Thanks to the moderator's advice, I will try my best to fix that variable display issue.
Floor 6 Posted 2007-09-23 12:42 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Floor 7 Posted 2007-09-23 14:36 ·  中国 安徽 宣城 广德市 电信
新手上路
Credits 18
Posts 10
Joined 2006-05-14 03:27
20-year member
UID 55495
Gender Male
Status Offline
Floor 8 Posted 2007-09-23 17:03 ·  中国 广东 广州 电信
初级用户
★★
Credits 172
Posts 54
Joined 2007-01-02 10:38
19-year member
UID 75260
Gender Male
Status Offline
Can the 7th floor describe how exactly the operation failed?
Floor 9 Posted 2007-09-23 18:38 ·  中国 浙江 宁波 电信
初级用户
Credits 82
Posts 30
Joined 2007-07-03 13:55
18-year member
UID 93029
Gender Male
Status Offline
Dizzy
It shows that I can't connect to the Internet.
I can post a thread. Does that mean I have already connected to the Internet?
Floor 10 Posted 2007-09-23 19:41 ·  中国 广东 广州 电信
初级用户
★★
Credits 172
Posts 54
Joined 2007-01-02 10:38
19-year member
UID 75260
Gender Male
Status Offline
Re: Post 9:
As long as your internet speed is sufficient and you can connect to the following websites normally, my batch script can run normally.

http://www.ip138.com
http://weather.news.qq.com
http://kumho.lin.googlepages.com
Floor 11 Posted 2007-10-01 23:52 ·  中国 广东 广州 黄埔区 电信
初级用户
Credits 26
Posts 14
Joined 2006-01-14 22:35
20-year member
UID 48984
Status Offline
What a talented expert! I know nothing about BAT... So difficult!!
Floor 12 Posted 2007-10-06 13:07 ·  马来西亚
新手上路
Credits 18
Posts 9
Joined 2007-07-25 18:11
18-year member
UID 94020
Gender Male
Status Offline
Wow!
Admire the creativity of the original poster...
Floor 13 Posted 2007-12-06 08:31 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
The owner's entire code is missing "", using "" will make the code more stable

~3,-1TEMP\your_location.txt
The system cannot find the file E:\TEMP\XP-TEMP\TEMP\your_location.txt.
┌───────────────────────────────────┐
│ Microsoft Windows XP Professional 5.1.2600 Service Pack 2 │
├───────────────────────────────────┤
│ 地区72小时天气预报 │
├───────────┬───────────┬───────────┤
│ │ │ │
├───────────┼───────────┼───────────┤
│ │ │ │
├───────────┼───────────┼───────────┤
│ │ │ │
└───────────┴───────────┴───────────┘



http://kumho.lin.googlepages.com
第一高手 第二高手

Floor 14 Posted 2007-12-06 13:22 ·  中国 广东 东莞 电信
新手上路
Credits 12
Posts 6
Joined 2007-01-25 04:57
19-year member
UID 77596
Gender Male
Status Offline
LZ. It didn't run successfully. The same error as the upstairs...
西安阳光:http://www.sun029.com
Floor 15 Posted 2007-12-07 14:18 ·  中国 广东 广州 天河区 电信
初级用户
Credits 98
Posts 39
Joined 2007-03-16 11:19
19-year member
UID 81943
Gender Male
Status Offline
Forum Jump: