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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
| Private Function Dir_NotBin(ByVal CurDir As String) As String
If Microsoft.VisualBasic.Right(CurDir, 4) = "\bin" Then
Return Mid(CurDir, 1, Len(CurDir) - 4)
Else
Return CurDir
End If
End Function
Private Function HTML2CHAR(ByVal S As String) As String
Dim P1 As Integer = -1
Dim P9 As Integer
Dim V As Integer
'
While P1 <> 0
P1 = InStr(S, "&#")
If P1 > 0 Then
P9 = InStr(P1, S, ";")
V = Val(Mid(S, P1 + 2, P9 - P1))
S = Mid(S, 1, P1 - 1) & Chr(V) & Mid(S, P9 + 1)
End If
End While
Return S
End Function
Dim DNL_FILE As String = Nothing
Public Structure WX_DATA_STRUC
Dim LOCATION As String
Dim TIME_OBS As String
Dim ICON As String
Dim CONDITIONS As String
Dim TEMPERATURE As String
Dim CHILL As String
Dim PRESSURE As String
Dim PRESS_TEND As String
Dim PRESS_ICON As String
Dim DEW_POINT As String
Dim HUMIDITY As String
Dim VISIBILITY As String
Dim WIND_SPD As String
Dim WIND_DIR As String
Dim SUNRISE As String
Dim SUNSET As String
Dim PRECIP As String
Dim PRECIP1h As String
Dim UV As String
Dim TEMP_HAUT As String
Dim TEMP_BASSE As String
End Structure
Dim WX_DATA As WX_DATA_STRUC
Private Sub EXEC_JOB()
DNLD_PAGE()
ANLZ_PAGE()
DSPL_DATA()
End Sub
Private Sub DNLD_PAGE()
Dim F As Integer = FreeFile()
Dim WEB_CLIENT As New WebClient
Dim DATA_BUFFER As Byte()
Dim DOWNLOAD_DATA As String
Dim TRANS_DATA As String
Dim I As Integer = 0
Dim X As String = Nothing
Dim Path1 As String = GetAppData()
Directory.CreateDirectory(Path1)
Dim path As String = (Path1)
Dim SRC_FILE As String = path & "\meteo"
DNL_FILE = SRC_FILE & ".temporaire" & ".smw"
Try
DATA_BUFFER = WEB_CLIENT.DownloadData(My.Settings.Lien_Ville)
DOWNLOAD_DATA = System.Text.Encoding.UTF8.GetString(DATA_BUFFER)
X = ""
For I = 0 To DOWNLOAD_DATA.Length - 1
X += DOWNLOAD_DATA.Chars(I)
Next
TRANS_DATA = HTML2CHAR(X)
FileOpen(F, DNL_FILE, OpenMode.Output, OpenAccess.Write)
Print(F, X)
FileClose(F)
FileOpen(F, SRC_FILE & ".smw", OpenMode.Output, OpenAccess.Write)
Print(F, TRANS_DATA)
FileClose(F)
Catch ex As Exception
'MsgBox(REMOTE_URL & vbCrLf & ex.Message)
'Me.Close()
End Try
End Sub
Private Sub ANLZ_PAGE()
Dim F As Integer = FreeFile()
Dim EOI As Boolean = False
Dim WRK As Boolean = False
'
Dim P, P1, P2 As Integer
Dim X As String
Dim S As String = Nothing
Dim Z As String
Try
FileOpen(F, DNL_FILE, OpenMode.Input, OpenAccess.Read)
Catch ex As Exception
End Try
Try
While Not EOI
If EOF(F) Then
EOI = True
Else
X = LineInput(F)
fenetre1.TEMPORAIRE.Text = X
S = fenetre1.TEMPORAIRE.Text
P = InStr(S, BALISE_LOCATION_START)
If P > 0 Then
S = Mid(S, P + BALISE_LOCATION_START.Length)
EOI = True
WRK = True
End If
End If
End While
Catch ex As Exception
My.Settings.JMC_SM_Connexion_internet_défaillante = True
End Try
FileClose(F)
Try
If WRK Then
Dim P0 As Integer
'/***** NOYAU DU TRAITEMENT *****/
'
'P = InStr(S, BALISE_LOCATION_STOP)
'WX_DATA.LOCATION = Mid(S, 1, P - 1)
'P = InStr(S, BALISE_WXCONDITIONS_START)
'S = Mid(S, P + BALISE_WXCONDITIONS_START.Length)
Dim S1 As String
S1 = S
P = InStr(S, BALISE_TIME_OBS_START)
S = Mid(S, P + BALISE_TIME_OBS_START.Length)
WX_DATA.TIME_OBS = Mid(S, 1, InStr(S, BALISE_TIME_OBS_STOP) - 1)
P = InStr(S, BALISE_ICON_START)
S = Mid(S, P + BALISE_ICON_START.Length)
WX_DATA.ICON = Mid(S, 1, InStr(S, BALISE_ICON_STOP) - 1)
P = InStr(S, BALISE_CONDITIONS_START)
S = Mid(S, P + BALISE_CONDITIONS_START.Length)
WX_DATA.CONDITIONS = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_CONDITIONS_STOP) - 1))
P = InStr(S, BALISE_TEMPERATURE_START)
S = Mid(S, P + BALISE_TEMPERATURE_START.Length)
WX_DATA.TEMPERATURE = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_TEMPERATURE_STOP) - 1))
P = InStr(S, BALISE_CHILL_START)
S = Mid(S, P + BALISE_CHILL_START.Length)
WX_DATA.CHILL = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_CHILL_STOP) - 1))
P = InStr(S, BALISE_PRESSURE_START)
S = Mid(S, P + BALISE_PRESSURE_START.Length)
P1 = InStr(S, BALISE_PRESSURE_STOP1)
P2 = InStr(S, BALISE_PRESSURE_STOP2)
If P2 = 0 Then ' pas d'indication de tendance barométrique
WX_DATA.PRESSURE = Mid(S, 1, InStr(S, BALISE_PRESSURE_STOP1) - 1)
Else
WX_DATA.PRESSURE = Mid(S, 1, InStr(S, BALISE_PRESSURE_STOP2) - 1)
P0 = InStr(S, "../pt")
If P0 > 0 Then
WX_DATA.PRESS_ICON = Mid(S, P0 + 3, 9)
P0 = InStr(WX_DATA.PRESS_ICON, ".gif")
WX_DATA.PRESS_ICON = Mid(WX_DATA.PRESS_ICON, 1, P0 + 3)
End If
'P = InStr(S, BALISE_PRESS_TEND_START)
'S = Mid(S, P + BALISE_PRESS_TEND_START.Length + 2)
'WX_DATA.PRESS_TEND = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_PRESS_TEND_STOP) - 1))
End If
P = InStr(S, BALISE_DEW_POINT_START)
S = Mid(S, P + BALISE_DEW_POINT_START.Length)
WX_DATA.DEW_POINT = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_DEW_POINT_STOP) - 1))
P = InStr(S, BALISE_HUMIDITY_START)
S = Mid(S, P + BALISE_HUMIDITY_START.Length)
WX_DATA.HUMIDITY = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_HUMIDITY_STOP) - 1))
P = InStr(S, BALISE_VISIBILITY_START)
S = Mid(S, P + BALISE_VISIBILITY_START.Length)
WX_DATA.VISIBILITY = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_VISIBILITY_STOP) - 1))
Z = S
P = InStr(S, BALISE_WIND_SPD_START)
S = Mid(S, P + BALISE_WIND_SPD_START.Length)
WX_DATA.WIND_SPD = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_WIND_SPD_STOP) + 3))
P = InStr(S, BALISE_WIND_DIR_START)
If P > 0 And P < 150 Then
S = Mid(S, P + BALISE_WIND_DIR_START.Length)
WX_DATA.WIND_DIR = HTML2CHAR(Mid(S, 1, InStr(S, BALISE_WIND_DIR_STOP) - 1))
Else
WX_DATA.WIND_DIR = ""
End If
P = InStr(Z, BALISE_SUNRISE_START)
Z = Mid(Z, P + BALISE_SUNRISE_START.Length)
WX_DATA.SUNRISE = Mid(Z, 1, InStr(Z, BALISE_SUNRISE_STOP) - 1)
P = InStr(Z, BALISE_SUNSET_START)
Z = Mid(Z, P + BALISE_SUNSET_START.Length)
WX_DATA.SUNSET = Mid(Z, 1, InStr(Z, BALISE_SUNSET_STOP) - 1)
P = InStr(S1, BALISE_PRECIP1h_START)
S1 = Mid(S1, P + BALISE_PRECIP1h_START.Length)
WX_DATA.PRECIP1h = Mid(S1, 1, InStr(S1, BALISE_PRECIP1h_STOP) - 1)
If WX_DATA.PRECIP1h = "NA" Then
WX_DATA.PRECIP1h = "0 mm"
End If
P = InStr(S1, BALISE_PRECIP_START)
S1 = Mid(S1, P + BALISE_PRECIP_START.Length)
WX_DATA.PRECIP = Mid(S1, 1, InStr(S1, BALISE_PRECIP_STOP) - 1)
P = InStr(S1, BALISE_UV_START)
S1 = Mid(S1, P + BALISE_UV_START.Length)
WX_DATA.UV = Mid(S1, 1, InStr(S1, BALISE_UV_STOP) - 1)
P = InStr(S1, BALISE_TEMP_HAUT_START)
S1 = Mid(S1, P + BALISE_TEMP_HAUT_START.Length)
WX_DATA.TEMP_HAUT = Mid(S1, 1, InStr(S1, BALISE_TEMP_HAUT_STOP) - 1)
P = InStr(S1, BALISE_TEMP_BASSE_START)
S1 = Mid(S1, P + BALISE_TEMP_BASSE_START.Length)
WX_DATA.TEMP_BASSE = Mid(S1, 1, InStr(S1, BALISE_TEMP_BASSE_STOP) - 1)
GC.Collect()
Else
End If
Catch ex As Exception
fenetre1.observation_heure.Text = "ND"
fenetre1.Conditions_actuelles.Text = "Indisponible"
fenetre1.Temperature_texte.Text = "ND"
fenetre1.température_resentie_résultat.Text = "ND"
fenetre1.pression_resultat.Text = "ND"
'fenetre1.pression_etat_resultat.Text = WX_DATA.PRESS_TEND
fenetre1.rosée_resultat.Text = "ND"
fenetre1.humidité_resultat.Text = "ND"
fenetre1.visibilité_resultat.Text = "ND"
fenetre1.vent_vitesse_resultat.Text = "ND"
fenetre1.vent_direction_resultat.Text = "ND"
fenetre1.levée_texte.Text = "ND"
fenetre1.couché_texte.Text = "ND"
fenetre1.precipitation_resultat.Text = "ND"
fenetre1.précipitation_dernière_heure.Text = "ND"
fenetre1.indiceUV_resultat.Text = "ND"
fenetre1.température_basse.Text = "ND"
fenetre1.température_haute.Text = "ND"
End Try
End Sub
Private Sub DSPL_DATA()
If My.Settings.JMC_SM_Connexion_internet_défaillante = False Then
WX_IMG_INDEX = Val(WX_DATA.ICON)
fenetre1.Icone_météo.Image = fenetre1.Icônes_temps.Images.Item(WX_IMG_INDEX)
fenetre1.observation_heure.Text = WX_DATA.TIME_OBS
fenetre1.Conditions_actuelles.Text = WX_DATA.CONDITIONS
fenetre1.Temperature_texte.Text = WX_DATA.TEMPERATURE
fenetre1.température_resentie_résultat.Text = WX_DATA.CHILL
fenetre1.pression_resultat.Text = WX_DATA.PRESSURE
fenetre1.rosée_resultat.Text = WX_DATA.DEW_POINT
fenetre1.humidité_resultat.Text = WX_DATA.HUMIDITY
fenetre1.visibilité_resultat.Text = WX_DATA.VISIBILITY
fenetre1.vent_vitesse_resultat.Text = WX_DATA.WIND_SPD
fenetre1.vent_direction_resultat.Text = WX_DATA.WIND_DIR
fenetre1.levée_texte.Text = WX_DATA.SUNRISE
fenetre1.couché_texte.Text = WX_DATA.SUNSET
fenetre1.precipitation_resultat.Text = WX_DATA.PRECIP
fenetre1.précipitation_dernière_heure.Text = WX_DATA.PRECIP1h
fenetre1.indiceUV_resultat.Text = WX_DATA.UV
fenetre1.température_basse.Text = WX_DATA.TEMP_BASSE
fenetre1.température_haute.Text = WX_DATA.TEMP_HAUT
GC.Collect()
End If
End Sub |
Partager