@CletusSnow
@JRace
Give this version a shot, guys:
Here, I've taken out the powershell commands and swapped this over to using our native QB64PE tcp/ip connections to download from the internet. I'm thinking this should work for everyone without any issues.
(This may even work for Linux/Mac folks, if you can supply your lat/lon coordinates for it. (Or ip address, as we use it to look up your lat/lon for you.)
@JRace
Give this version a shot, guys:
Code: (Select All)
$Unstable:Http
$Console:Only
_Dest _Console
ip$ = GetPublicIP$
Print "Your IP Address is:"; ip$
Print
Lat_Long ip$, lat, lon
Print "Your Latitude and Longitude is: "; lat, lon
Print
Print "For your location, the following is true for Xmas day:"
SunStuff lat, lon, 12, 25, 2024
Function GetPublicIP$
f = FreeFile
Open "tempPIP.txt" For Output As #f: Close f
Shell _Hide "cmd /c nslookup myip.opendns.com resolver1.opendns.com>tempPIP.txt"
Open "tempPIP.txt" For Input As #f
If LOF(f) Then
Do
Line Input #f, temp$
If temp$ <> "" Then last$ = temp$ 'there's a blank line after the data we need.
' Ignore it. What we want is the last line of info generated here.
Loop Until EOF(1)
End If
Close f
l = _InStrRev(last$, "Address:")
If l Then GetPublicIP$ = Mid$(last$, l + 10)
Kill "tempPIP.txt"
End Function
Sub Lat_Long (ip$, lat, lon)
out$ = "www.ip-api.com/line/" + ip$ + "?fields=lat"
t$ = Download$(out$, junk&)
lat = Val(t$)
out$ = "www.ip-api.com/line/" + ip$ + "?fields=lon"
t$ = Download$(out$, junk&)
lon = Val(t$)
End Sub
Sub SunStuff (lat, lon, month, day, year)
out$ = "api.sunrise-sunset.org/json?lat="
out$ = out$ + _Trim$(Str$(lat)) + "&lng="
out$ = out$ + _Trim$(Str$(lon)) + "&date="
d$ = _Trim$(Str$(year)) + _Trim$(Str$(month)) + _Trim$(Str$(day))
out$ = out$ + d$
t$ = Download$(out$, junk&)
'strip off unwanted stuff
l = InStr(t$, ":{"): t$ = Mid$(t$, l + 2)
Do
l = InStr(t$, Chr$(34))
t$ = Left$(t$, l - 1) + Mid$(t$, l + 1)
Loop Until l = 0
Do
l = InStr(t$, "_")
t$ = Left$(t$, l - 1) + " " + Mid$(t$, l + 1)
Loop Until l = 0
t$ = _Trim$(t$)
t$ = Left$(t$, Len(t$) - 1)
Do
l = InStr(t$, ",")
If l = 0 Then Exit Do
whole$ = Left$(t$, l)
l$ = Left$(whole$, InStr(whole$, ":") - 1)
r$ = Mid$(whole$, InStr(whole$, ":") + 1)
r$ = Left$(r$, Len(r$) - 1)
Print l$; " is "; r$
t$ = Mid$(t$, l + 1)
Loop
Close 1
End Sub
' Content of the HTTP response is returned. The statusCode is also assigned.
Function Download$ (url As String, statusCode As Long)
h& = _OpenClient("HTTP:" + url)
statusCode = _StatusCode(h&)
While Not EOF(h&)
_Limit 60
Get #h&, , s$
content$ = content$ + s$
Wend
Close #h&
Download$ = content$
End Function
Here, I've taken out the powershell commands and swapped this over to using our native QB64PE tcp/ip connections to download from the internet. I'm thinking this should work for everyone without any issues.
(This may even work for Linux/Mac folks, if you can supply your lat/lon coordinates for it. (Or ip address, as we use it to look up your lat/lon for you.)