Zoals de topictitel al aangeeft: ik ben een absolute newbie op het gebied van VBS. De enige (kleine) scriptingervaring die ik heb is met PowerBuilder, en das alweer een tijdje geleden.
Het probleem: in het systeemmonitoring programma CoolMon gebruik ik een script om van www.weather.com het weer op te halen (niet zelf gemaakt
), dit script parsed van www.weather.com de data die ik nodig heb en zet dit in een TXT file, allemaal netjes onder elkaar.
Dit is het script:
Nu is het 'probleem' dat op www.weather.com de tijd die de laatste update aangeeft met AM/PM werkt (vb: Last update 7:55 PM). Nu zou ik dit graag willen omzetten naar een 24 uurs systeem (vb: Last update 19:55). Volgens mij moet dit niet zo moeilijk zijn.
Nu heb ik dit al gevraagd op het CoolMon forum, en daar kwam iemand met het volgende script:
Ik snap dit script wel, ik heb alleen géén idee of het ook echt werkt, en hoe ik het in het eerste script moet verwerken... Op het CoolMon forum kon men mij verder niet helpen.
Ik hoop dat iemand mij stap voor stap kan uitleggen hoe ik dit op moet lossen. Ik weet dat het hier over het algemeen niet zo gewaardeerd wordt wanneer iemand met (bijna) 0,0 % verstand van het onderwerp een probleem op tafel gooit, maar ik hoop hier ook iets van te leren.
Ow: 1000x sorry voor de lay-out verneuking, maar ik weet anders ook niet hoe ik het goed leesbaar moet plaatsen.
Het probleem: in het systeemmonitoring programma CoolMon gebruik ik een script om van www.weather.com het weer op te halen (niet zelf gemaakt
Dit is het script:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
| '***************************************************************************************************
set pinger = CreateObject("DSPing.Ping")
if pinger.DoPing("www.tweakers.net") <> 0 then WScript.Quit()
' Change this to the URL of you local city.
const conURLSrc = "http://www.weather.com/outlook/travel/local/NLXX0016?whatprefs=&y=9&x=8"
' Change this to where you want the output file
const outFile = "C:\Program Files\CoolMon\Scripts\weather.txt"
' Only set metric=ture if you want the script to perform conversions to metric.
' (ie. weather.com is displayed in english but you want the output of this script to be in metric)
' I recommend that you set metric=false and instead set up weather.com in the unit of your choice.
' (ie if you want metric units go to weather.com and choose "Show this page in: metric units")
metric = true
' This is the output of the script:
' Station
' Updated
' Forecast
' Current Temp
' Feels Like Temp
' UV Index
' Wind
' Dew Point
' Humidity
' Visibility
' Barometer
' forecast Day
' forecast Date
' forecast Condition
' forecast High
' forecast Low
' forecast Precipitation
' The forecast loops until all the forecasts are displayed.
'***************************************************************************************************
dim data
dim fDays(10),fDates(10),fConditions(10),fHigh(10),fLow(10),fPrec(10)
set http = createobject("microsoft.xmlhttp")
http.open "GET",conURLSrc,False
http.send
htmlPage = http.responsetext
Set fso = CreateObject("Scripting.FileSystemObject")
set fOutput = fso.CreateTextFile(outFile,true)
'Set ts = fso.OpenTextFile("w2.txt", 1)
'htmlPage = ts.ReadAll
Set data = CreateObject("Scripting.Dictionary")
data.add "Station",reg (htmlPage,"<!-- insert reported/last updated info -->[\S\s]*?As reported at (.*?) ")
data.add "Updated",reg (htmlPage,"<!-- insert reported/last updated info -->[\S\s]*?As reported at .*?at (\d+:\d+ .*?) ")
data.add "Forecast",reg (htmlPage,"><!-- insert forecast -->(.*?)<")
data.add "Current Temp",convert(reg (htmlPage,"<!-- insert current tempature --> <B>(.*?)</B>"),-1,"°F","°")
data.add "Feels Like Temp",convert(reg (htmlPage,"<!-- insert feels like temp -->(.*?)<"),-1,"°F","°")
data.add "UV Index",reg (htmlPage,"<!-- insert UV index -->(.*?)<")
data.add "Wind",convert(reg (htmlPage,"<!-- insert wind -->(.*?)<"),1.6,"mph","kph")
data.add "Dew Point",convert(reg (htmlPage,"<!-- insert dew point -->(.*?)<"),-1,"°F","°")
data.add "Humidity",reg (htmlPage,"<!-- insert humidity -->(.*?)<")
data.add "Visibility",convert(reg (htmlPage,"<!-- insert visibility -->(.*?)<"),1.6,"miles","kilometers")
data.add "Barometer",convert(reg (htmlPage,"<!-- insert pressure -->(.*?)<"),.03385,"inches","torr")
Dim regEx
Set regEx = New RegExp
regEx.Global = True
regEx.Pattern = "<!-- insert day with link -->(?:<.*?>)*(.*?)<.*?<!-- insert date -->(.*?)<[\S\s]*?<!-- insert forecast -->(.*?)<[\S\s]*?<!-- insert high -->(.*?)<!-- insert low -->(.*?)<[\S\s]*?<!-- insert precip. chance -->(.*?)<"
'regEx.Pattern = "(?:(?:<!-- insert load change day/date here --><.*?>)|(?:<!-- insert no link day name here -->))\s*(.*?)(?:</A>)*?<BR>(.*?)\s*<[\S\s]*?<TD CLASS=""dataText"".*?>([\S\s]*?)<[\S\s]*?<TD CLASS=""dataText"".*?>([\S\s]*?)<[\S\s]*?<TD CLASS=""dataText"".*?>([\S\s]*?)<"
set matches = regEx.Execute(htmlPage)
i=0
for each match in matches
fDays(i) = deHTML(match.SubMatches(0))
fDates(i) = deHTML(match.SubMatches(1))
fConditions(i) = deHTML(match.SubMatches(2))
fHigh(i) = convert(deHTML(replace(match.SubMatches(3),"/","")),-1,"","")
fLow(i) = convert(deHTML(match.SubMatches(4)),-1,"","")
fPrec(i) = deHTML(match.SubMatches(5))
i=i+1
next
data.add "Time Checked",Date & " " & Time
keys = data.Keys
For i = 0 To data.Count -1
fOutput.writeLine data.Item(keys(i))
Next
for i = 0 To 9
fOutput.writeLine fDays(i)
fOutput.writeLine fDates(i)
fOutput.writeLine fConditions(i)
fOutput.writeLine fHigh(i)
fOutput.writeLine fLow(i)
fOutput.writeLine fPrec(i)
next
fOutput.close
function reg(target, pattern)
Dim regEx, temp
Set regEx = New RegExp
regEx.Global = False
regEx.Pattern = pattern
if regEx.Test(target) then
temp = regEx.Execute(target)(0).SubMatches(0)
temp = deHTML(temp)
reg = temp
else
reg = "N/A"
end if
end function
function deHTML(st)
st = replace(st,vbLf,"")
st = replace(st,vbCr,"")
st = replace(st,vbCrLf,"")
st = replace(st," "," ")
st = replace(st,"°","°")
st = trim(st)
deHTML = st
end function
function convert(str,factor,find,rep)
Dim regEx, match, temp
Set regEx = New RegExp
regEx.Global = False
if metric then
if (inStr(str,find)>0) then
str = replace(str,find,rep)
regEx.Pattern = "(.*?)(\d+(?:\.\d+){0,1})(.*)"
if regEx.Test(str) then
Set match = regEx.Execute(str)(0)
temp = match.SubMatches(1)
if factor = -1 then
temp = round((temp-32)*(5/9))
else
temp = round(temp*factor,2)
end if
str = match.SubMatches(0) & temp & match.SubMatches(2)
end if
end if
end if
convert = str
end function |
Nu is het 'probleem' dat op www.weather.com de tijd die de laatste update aangeeft met AM/PM werkt (vb: Last update 7:55 PM). Nu zou ik dit graag willen omzetten naar een 24 uurs systeem (vb: Last update 19:55). Volgens mij moet dit niet zo moeilijk zijn.
Nu heb ik dit al gevraagd op het CoolMon forum, en daar kwam iemand met het volgende script:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| data.add "Time Checked",Date & " " & Time keys = data.Keys For i = 0 To data.Count -1 fOutput.writeLine data.Item(keys(i)) array24hr = split(Time, " ") hrmin = split(array24hr(0), ":") If array24hr(1) = "PM" then time24hr = (CInt(hrmin(0)) + 12) * 100 + CInt(hrmin(1)) ElseIf array24hr(1) = "AM" then time24hr = CInt(hrmin(0)) * 100 + CInt(hrmin(1)) End if Next |
Ik snap dit script wel, ik heb alleen géén idee of het ook echt werkt, en hoe ik het in het eerste script moet verwerken... Op het CoolMon forum kon men mij verder niet helpen.
Ik hoop dat iemand mij stap voor stap kan uitleggen hoe ik dit op moet lossen. Ik weet dat het hier over het algemeen niet zo gewaardeerd wordt wanneer iemand met (bijna) 0,0 % verstand van het onderwerp een probleem op tafel gooit, maar ik hoop hier ook iets van te leren.
Ow: 1000x sorry voor de lay-out verneuking, maar ik weet anders ook niet hoe ik het goed leesbaar moet plaatsen.
[ Voor 0% gewijzigd door posttoast op 18-10-2002 10:30 . Reden: Excuses ]