Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Christmas Info (Windows Users)
#8
@CletusSnow
@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.)
Reply


Messages In This Thread
Christmas Info (Windows Users) - by SMcNeill - 10-17-2024, 05:32 PM
RE: Christmas Info (Windows Users) - by SMcNeill - 10-18-2024, 07:10 AM
RE: Christmas Info (Windows Users) - by SMcNeill - 10-18-2024, 01:09 PM
RE: Christmas Info (Windows Users) - by JRace - 10-19-2024, 06:52 AM
RE: Christmas Info (Windows Users) - by SMcNeill - 10-20-2024, 12:03 PM
RE: Christmas Info (Windows Users) - by JRace - 10-20-2024, 12:28 PM



Users browsing this thread: 6 Guest(s)