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
| '16.5d LECTURE DE DEVISES AU FORMAT JSON
Public Sub MajDevises(Optional bilan As Boolean = False)
Dim http As MSXML2.ServerXMLHTTP, Liste As String, rado As New adodb.Recordset, nb As Integer, i As Integer, s As String
100 nb = 0 'nombre de devises mises à jour
102 Liste = ""
'Lecture du flux
If Not Mode_debug Then On Error GoTo suite:
105 Set http = New MSXML2.ServerXMLHTTP
106 http.Open "GET", "http://api.fixer.io/latest", False
107 http.send ""
'En cas de réussite, le code renvoyé est 200
110 If http.Status <> 200 Then
111 nb = http.Status
112 Liste = ""
Else
115 Liste = http.responseText
End If
116 Set http = Nothing
'MsgBox liste
'{"base":"EUR","date":"2016-06-22","rates":{"AUD":1.5033,"BGN":1.9558,"BRL":3.8357,"CAD":1.4399,"CHF":1.083,"CNY":7.4227,"CZK":27.071,"DKK":7.4384,"GBP":0.76793,"HKD":8.7524,"HRK":7.52,"HUF":314.42,"IDR":14988.34,"ILS":4.3471,"INR":76.1553,"JPY":118.01,"KRW":1297.62,"MXN":21.0048,"MYR":4.543,"NOK":9.3555,"NZD":1.5732,"PHP":52.434,"PLN":4.3785,"RON":4.526,"RUB":72.266,"SEK":9.3468,"SGD":1.5112,"THB":39.716,"TRY":3.275,"USD":1.1283,"ZAR":16.577}}
suite:
If Not Mode_debug Then On Error GoTo err:
120 If Liste > "" Then
122 rado.Open "SELECT * FROM devises WHERE code3<>'EUR' order by code3;", cnx, adOpenStatic
124 While Not rado.EOF
126 i = InStr(Liste, """" & rado!code3 & """:")
128 If i > 0 Then
130 s = Mid(Liste, i + 6, 12)
132 If InStr(s, ",") > 1 Then s = Left(s, InStr(s, ",") - 1)
133 s = Replace(s, ".", ",")
134 If IsNumeric(s) And s > "0" Then
136 cnx.Execute "UPDATE devises SET taux=" & Num(1 / s, 6) & ", Dmodif=" & IIf(msql, "get", "") & "date() WHERE code3='" & rado!code3 & "'"
138 nb = nb + 1
End If: End If
140 rado.MoveNext
Wend
End If
142 If bilan Then MsgBox nb & " devises actualisées."
Set rado = Nothing
Exit Sub
err: Call message("Erreur " & err.Number & "/" & Erl & " dans api_stock.MajDevises(statut " & nb & ") : " & err.description)
End Sub |
Partager