Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Christmas Info (Windows Users)
#7
The program doesn't work for me even with @CletusSnow's fix.

It looks like Invoke-Webrequest was introduced in PS 3, so it doesn't work on my lowly Win7 box which is stuck with PS 2.0.  (I've tried upgrading, but the MS installer package laughs in derision and shuts down.)

If someone needs to check their PS version, they can type $PSVersionTable at the PS prompt.


Edit: got it to work using curl instead of PowersHell:
Code: (Select All)
$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, 2020


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$ = "powershell.exe -c " + Chr$(34) + "Invoke-Webrequest 'ip-api.com/line/"
    out$ = "curl -s -o ./temp.txt " + Chr$(34) + "http://www.ip-api.com/line/"
    out$ = out$ + ip$
    out$ = out$ + "?fields=lat,lon" + Chr$(34)
    'out$ = out$ + "?fields=lat,lon' -OutFile '.\temp.txt'" + Chr$(34)
    Shell _Hide out$
    Open "temp.txt" For Input As #1
    Input #1, lat
    Input #1, lon
    Close 1
End Sub

Sub SunStuff (lat, lon, month, day, year)
    'out$ = "powershell.exe -c " + Chr$(34) + "Invoke-Webrequest 'https://api.sunrise-sunset.org/json?lat="
    out$ = "curl -s -o temp.txt " + Chr$(34) + "http://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$ + "'   -OutFile '.\temp.txt'"
    Shell out$
    Open "temp.txt" For Binary As #1
    t$ = Space$(LOF(1))
    Get #1, 1, t$
    '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



   

Man, that late sunrise/sunset in the wintertime really messes with my sleep schedule.
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: 1 Guest(s)