Her er fikset versjon. 🙂
Krever MyBring-konto.
Man må legge inn rett postnummer, e-postadresse og API-key på rett sted i koden.
Sub Main(ByVal params As Object)
Dim devRef As Integer = 6560
Dim url As String = "https://api.bring.com/address/api/no/postal-codes/POSTNUMMER/mailbox-delivery-dates"
Dim source As String = ""
Try
Using client As New System.Net.WebClient
client.Headers.Add("x-mybring-api-uid", "EPOST-ADRESSE")
client.Headers.Add("x-mybring-api-key", "API KEY")
client.BaseAddress = url
source = client.DownloadString(url)
End Using
Dim json As Object = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Object)(source)
hs.writelog("Posten", json.tostring)
Dim output As String = json.item("delivery_dates").item(0).tostring
hs.writelog("Posten", output)
Dim ci = New System.Globalization.CultureInfo("nb-NO")
Dim nestePostdag As Date = DateTime.Parse((output), ci)
Dim dagerTilPost As Integer = nestePostdag.Date.Subtract(Now.Date).Days
If dagerTilPost = 0 Then
output = "I dag"
Else If dagerTilPost = 1 Then
output = "I morgen"
Else
output = nestePostdag.ToString("ddd d. MMM", ci)
End If
hs.SetDeviceValueByRef(devRef, dagerTilPost, True)
hs.SetDeviceString(devRef, output, False)
Catch ex As Exception
hs.SetDeviceValueByRef(devRef, -1, True)
hs.SetDeviceString(devRef, "Feil: " & ex.Message, False)
End Try
End Sub