This repository was archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
This repository was archived by the owner on Nov 28, 2023. It is now read-only.
RocketLaunces has old data #48
Copy link
Copy link
Open
Description
I've never written in b4x, but I thought I'd give it a whirl (it could probably use some cleanup). I know this project is dead. But I figured I'd just drop this nugget here.
This code below should get fix the problem.
Sub Class_Globals
Dim App As AWTRIX
'Declare your variables here
Dim RocketName As String
Dim TimeString As String
End Sub
' ignore
public Sub GetNiceName() As String
Return App.Name
End Sub
' ignore
public Sub Run(Tag As String, Params As Map) As Object
Return App.interface(Tag,Params)
End Sub
' Config your App
Public Sub Initialize() As String
App.Initialize(Me,"App")
'App name (must be unique, avoid spaces)
App.Name="RocketLaunch"
'Version of the App
App.Version="1.1"
'Description of the App. You can use HTML to format it
App.Description="Show next rocket launch"
App.Author="Blueforcer"
App.CoverIcon=671
'How many downloadhandlers should be generated
App.downloads=1
'IconIDs from AWTRIXER. You can add multiple if you want to display them at the same time
App.Icons=Array As Int(671)
'Tickinterval in ms (should be 65 by default, for smooth scrolling))
App.Tick=65
'If set to true AWTRIX will wait for the "finish" command before switch to the next app.
App.Lock=True
App.MakeSettings
Return "AWTRIX20"
End Sub
'Called with every update from Awtrix
'return one URL for each downloadhandler
Sub App_startDownload(jobNr As Int)
Select jobNr
Case 1
' Updated the API address
App.Download("https://ll.thespacedevs.com/2.2.0/launch/upcoming/?hide_recent_previous=true&limit=1")
End Select
End Sub
'process the response from each download handler
'if youre working with JSONs you can use this online parser
'to generate the code automaticly
'https://json.blueforcer.de/
Sub App_evalJobResponse(Resp As JobResponse)
Try
If Resp.success Then
Select Resp.jobNr
Case 1
Dim parser As JSONParser
parser.Initialize(Resp.ResponseString)
Dim root As Map = parser.NextObject
Dim results As List = root.Get("results")
For Each collaunches As Map In results
Dim netstamp As String = collaunches.Get("net")
' Stores the current date format.
Dim CurrentDateFormat As String = DateTime.DateFormat
Dim launchtime As Long
Dim s As String
Dim sFormat As String
s = netstamp.Trim
s = s.SubString2(0,10) & " " & s.SubString(11)
s = s.SubString2(0,19) & " GMT"
sFormat = "yyyy-MM-dd HH:mm:ss Z"
DateTime.DateFormat = sFormat
launchtime = DateTime.DateParse(s) + DateTime.TimeZoneOffset
' Resets the previous date format.
DateTime.DateFormat = CurrentDateFormat
Dim rocket As Map = collaunches.Get("rocket")
Dim configuration As Map = rocket.Get("configuration")
RocketName = configuration.Get("name")
Dim p As Period=DateUtils.PeriodBetween(DateTime.Now,launchtime)
If p.Days=0 And p.Hours=0 Then
TimeString=p.Minutes & "M "& p.Seconds& "S"
End If
If p.Days=0 And p.Hours>0 Then
TimeString=p.Hours & "H " & p.Minutes & "M"
End If
If p.Days>0 Then
TimeString=p.Days & "D " & p.Hours & "H"
End If
If p.Days<0 Then
TimeString="0:00"
End If
Next
End Select
End If
Catch
Log("Error in: "& App.Name & CRLF & LastException)
Log("API response: " & CRLF & Resp.ResponseString)
End Try
End Sub
'With this sub you build your frame.
Sub App_genFrame
App.genText(RocketName& " T-0: " & TimeString,True,1,Null,True)
If App.scrollposition>9 Then
App.drawBMP(0,0,App.getIcon(671),8,8)
Else
If App.scrollposition>-8 Then
App.drawBMP(App.scrollposition-9,0,App.getIcon(671),8,8)
End If
End If
End Sub
Metadata
Metadata
Assignees
Labels
No labels