Author Topic: A quick program for folks to test  (Read 5693 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A quick program for folks to test
« Reply #15 on: December 25, 2020, 06:02:01 am »
@Bert22306, @johnno56

Give the following version a run, guys, and see what you get:

Code: QB64: [Select]
  1.  
  2. ip$ = GetPublicIP$
  3. PRINT "Your IP Address is:"; ip$
  4. Lat_Long ip$, lat, lon
  5. PRINT "Your Latitude and Longitude is: "; lat, lon
  6. PRINT "For your location, the following is true for Xmas day:"
  7. SunStuff lat, lon, 12, 25, 2020
  8.  
  9.  
  10. SUB DownloadURL (link$, file$)
  11.     f = FREEFILE
  12.     OPEN file$ FOR OUTPUT AS #f: CLOSE #f 'erase any old file of the same name
  13.     $IF WIN THEN
  14.         out$ = "powershell.exe -c " + CHR$(34) + "Invoke-Webrequest '" + link$ + "' -OutFile '" + file$ + "'" + CHR$(34)
  15.     $ELSE
  16.         out$ = "wget " + chr$(34) + link$ + " -O " + file$ + chr$(34)
  17.     $END IF
  18.     SHELL _HIDE out$
  19.  
  20.  
  21. FUNCTION GetPublicIP$
  22.     f = FREEFILE
  23.     OPEN "tempPIP.txt" FOR OUTPUT AS #f: CLOSE f
  24.     SHELL _HIDE "cmd /c nslookup myip.opendns.com resolver1.opendns.com>tempPIP.txt"
  25.  
  26.     OPEN "tempPIP.txt" FOR INPUT AS #f
  27.     IF LOF(f) THEN
  28.         DO
  29.             LINE INPUT #f, temp$
  30.             IF temp$ <> "" THEN last$ = temp$ 'there's a blank line after the data we need.
  31.             '                                 Ignore it.  What we want is the last line of info generated here.
  32.         LOOP UNTIL EOF(1)
  33.     END IF
  34.     CLOSE f
  35.     l = _INSTRREV(last$, "Address:")
  36.     IF l THEN GetPublicIP$ = MID$(last$, l + 10)
  37.     KILL "tempPIP.txt"
  38.  
  39. SUB Lat_Long (ip$, lat, lon)
  40.     f = FREEFILE
  41.     DownloadURL "ip-api.com/line/" + ip$ + "?fields=lat,lon", "temp.txt"
  42.     OPEN "temp.txt" FOR INPUT AS #f
  43.  
  44.     IF LOF(f) = 0 THEN CLOSE f: EXIT SUB 'something didn't download.  this info isn't available to parse.
  45.  
  46.     INPUT #f, lat
  47.     INPUT #f, lon
  48.     CLOSE f
  49.  
  50. SUB SunStuff (lat, lon, month, day, year)
  51.     d$ = _TRIM$(STR$(year)) + _TRIM$(STR$(month)) + _TRIM$(STR$(day))
  52.     link$ = "https://api.sunrise-sunset.org/json?lat=" + _TRIM$(STR$(lat)) + "&lng="
  53.     link$ = link$ + _TRIM$(STR$(lon)) + "&date=" + d$
  54.     DownloadURL link$, "temp.txt"
  55.     f = FREEFILE
  56.     OPEN "temp.txt" FOR BINARY AS #f
  57.  
  58.     IF LOF(f) = 0 THEN CLOSE f: EXIT SUB 'something didn't download.  this info isn't available to parse.
  59.  
  60.     t$ = SPACE$(LOF(f))
  61.     GET #1, 1, t$
  62.     CLOSE f
  63.  
  64.     'strip off unwanted stuff
  65.     l = INSTR(t$, ":{"): t$ = MID$(t$, l + 2)
  66.     DO
  67.         l = INSTR(t$, CHR$(34))
  68.         t$ = LEFT$(t$, l - 1) + MID$(t$, l + 1)
  69.     LOOP UNTIL l = 0
  70.     DO
  71.         l = INSTR(t$, "_")
  72.         t$ = LEFT$(t$, l - 1) + " " + MID$(t$, l + 1)
  73.     LOOP UNTIL l = 0
  74.     t$ = _TRIM$(t$)
  75.     t$ = LEFT$(t$, LEN(t$) - 1)
  76.  
  77.     DO
  78.         l = INSTR(t$, ",")
  79.         IF l = 0 THEN EXIT DO
  80.         whole$ = LEFT$(t$, l)
  81.         l$ = LEFT$(whole$, INSTR(whole$, ":") - 1)
  82.         r$ = MID$(whole$, INSTR(whole$, ":") + 1)
  83.         r$ = LEFT$(r$, LEN(r$) - 1)
  84.         PRINT l$; " is "; r$
  85.         t$ = MID$(t$, l + 1)
  86.     LOOP
  87.  

For Bert, I'm hoping that you'll basically run but see a whole lot of nothing, as we should error trap now for non-existent files.  You could always try running it as admin and see if that makes a difference on your work machine, but I imagine it's some sort of system limitation.  Powershell is only available from windows 7 up, so if your enterprise machines don't give proper permissions, or run on an older version of windows, then they're definitely not going to work.  A test just to make certain things fail properly, without crashing, would be nice in this case.  :)

For Johnno, I'm hoping that you get the same results now that everyone else does.  If not, uncomment out that _HIDE statement in the download SUB and let me know what the output is that you see.  wget comes with Linux (I think), so unless my syntax is wrong, or something, I'm thinking it should work for you.  If it does, I'll have a nice simple tool to add to my toolbox for downloading stuff from the web, which works with https files and is cross-compatible with our various OSes.  :D

For everyone else, it should run as before, without any changes.  At least, I hope it does...
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A quick program for folks to test
« Reply #16 on: December 25, 2020, 06:52:49 am »
And if all works well, the following version should now make adjustments to the time to account for your local time zone and current daylight saving time. 

Code: QB64: [Select]
  1. TYPE Sun_Data_type
  2.     value AS STRING
  3.  
  4. REDIM SHARED Sun(0) AS Sun_Data_type
  5.  
  6.  
  7.  
  8.  
  9. ip$ = GetPublicIP$
  10. PRINT "Your IP Address is:"; ip$
  11. Lat_Long ip$, lat, lon
  12. PRINT "Your Latitude and Longitude is: "; lat, lon
  13.  
  14. SunStuff lat, lon, 12, 25, 2020
  15. PRINT "For your location, the following is true for Xmas day:"
  16. FOR i = 1 TO UBOUND(Sun)
  17.     PRINT Sun(i).field; " = "; Sun(i).value
  18.  
  19.  
  20. FUNCTION GetHour (fromTime$)
  21.     'time should be hh:mm:ss WhateverM
  22.     l = INSTR(fromTime$, ":") '1st :
  23.     GetHour = VAL(LEFT$(fromTime$, l))
  24.  
  25. FUNCTION GetMinute (fromTime$)
  26.     'time should be hh:mm:ss WhateverM
  27.     l = INSTR(fromTime$, ":") '1st :
  28.     GetMinute = VAL(MID$(fromTime$, l + 1))
  29.  
  30.  
  31. FUNCTION GetSecond (fromTime$)
  32.     'time should be hh:mm:ss WhateverM
  33.     l = INSTR(fromTime$, ":") '1st :
  34.     l = INSTR(l + 1, fromTime$, ":") '2nd :
  35.     GetSecond = VAL(MID$(fromTime$, l + 1))
  36.  
  37.  
  38. FUNCTION GetTimeOffset
  39.     $IF WIN THEN
  40.         TYPE SYSTEMTIME
  41.             wYear AS _UNSIGNED INTEGER
  42.             wMonth AS _UNSIGNED INTEGER
  43.             wDayOfWeek AS _UNSIGNED INTEGER
  44.             wDay AS _UNSIGNED INTEGER
  45.             wHour AS _UNSIGNED INTEGER
  46.             wMinute AS _UNSIGNED INTEGER
  47.             wSecond AS _UNSIGNED INTEGER
  48.             wMilliseconds AS _UNSIGNED INTEGER
  49.         END TYPE
  50.  
  51.         TYPE TIME_ZONE_INFORMATION
  52.             Bias AS LONG
  53.             StandardName AS STRING * 64 'WCHAR      StandardName[32];
  54.             StandardDate AS SYSTEMTIME
  55.             StandardBias AS LONG
  56.             DaylightName AS STRING * 64 'WCHAR      DaylightName[32];
  57.             DaylightDate AS SYSTEMTIME
  58.             DaylightBias AS LONG
  59.         END TYPE
  60.  
  61.         DECLARE DYNAMIC LIBRARY "Kernel32"
  62.             SUB GetTimeZoneInformation (t AS TIME_ZONE_INFORMATION)
  63.         END DECLARE
  64.  
  65.         DIM t AS TIME_ZONE_INFORMATION
  66.         GetTimeZoneInformation t
  67.         GetTimeOffset = t.Bias
  68.     $END IF
  69.  
  70.  
  71. SUB DownloadURL (link$, file$)
  72.     f = FREEFILE
  73.     OPEN file$ FOR OUTPUT AS #f: CLOSE #f 'erase any old file of the same name
  74.     $IF WIN THEN
  75.         out$ = "powershell.exe -c " + CHR$(34) + "Invoke-Webrequest '" + link$ + "' -OutFile '" + file$ + "'" + CHR$(34)
  76.     $ELSE
  77.         out$ = "wget " + chr$(34) + link$ + " -O " + file$ + chr$(34)
  78.     $END IF
  79.     SHELL _HIDE out$
  80.  
  81.  
  82. FUNCTION GetPublicIP$
  83.     f = FREEFILE
  84.     OPEN "tempPIP.txt" FOR OUTPUT AS #f: CLOSE f
  85.     SHELL _HIDE "cmd /c nslookup myip.opendns.com resolver1.opendns.com>tempPIP.txt"
  86.  
  87.     OPEN "tempPIP.txt" FOR INPUT AS #f
  88.     IF LOF(f) THEN
  89.         DO
  90.             LINE INPUT #f, temp$
  91.             IF temp$ <> "" THEN last$ = temp$ 'there's a blank line after the data we need.
  92.             '                                 Ignore it.  What we want is the last line of info generated here.
  93.         LOOP UNTIL EOF(1)
  94.         l = _INSTRREV(last$, "Address:")
  95.         IF l THEN GetPublicIP$ = MID$(last$, l + 10)
  96.     END IF
  97.     CLOSE f
  98.     KILL "tempPIP.txt"
  99.  
  100. SUB Lat_Long (ip$, lat, lon)
  101.     f = FREEFILE
  102.     DownloadURL "ip-api.com/line/" + ip$ + "?fields=lat,lon", "temp.txt"
  103.     OPEN "temp.txt" FOR INPUT AS #f
  104.  
  105.     IF LOF(f) = 0 THEN CLOSE f: EXIT SUB 'something didn't download.  this info isn't available to parse.
  106.  
  107.     INPUT #f, lat
  108.     INPUT #f, lon
  109.     CLOSE f
  110.  
  111. SUB SunStuff (lat, lon, month, day, year)
  112.     d$ = _TRIM$(STR$(year)) + _TRIM$(STR$(month)) + _TRIM$(STR$(day))
  113.     link$ = "https://api.sunrise-sunset.org/json?lat=" + _TRIM$(STR$(lat)) + "&lng="
  114.     link$ = link$ + _TRIM$(STR$(lon)) + "&date=" + d$
  115.     DownloadURL link$, "temp.txt"
  116.     f = FREEFILE
  117.     OPEN "temp.txt" FOR BINARY AS #f
  118.  
  119.     IF LOF(f) = 0 THEN CLOSE f: EXIT SUB 'something didn't download.  this info isn't available to parse.
  120.  
  121.     t$ = SPACE$(LOF(f))
  122.     GET #1, 1, t$
  123.     CLOSE f
  124.  
  125.     'strip off unwanted stuff
  126.     l = INSTR(t$, ":{"): t$ = MID$(t$, l + 2) 'junk left of our initial data
  127.     DO
  128.         l = INSTR(t$, CHR$(34))
  129.         t$ = LEFT$(t$, l - 1) + MID$(t$, l + 1) 'remove all quotes completely from this data
  130.     LOOP UNTIL l = 0
  131.     DO
  132.         l = INSTR(t$, "_")
  133.         t$ = LEFT$(t$, l - 1) + " " + MID$(t$, l + 1) 'change all underscores to spaces in this data
  134.     LOOP UNTIL l = 0
  135.     t$ = _TRIM$(t$)
  136.     t$ = LEFT$(t$, LEN(t$) - 12) 'remove the last end of data }
  137.     PRINT t$
  138.  
  139.     'parse it down to field, data
  140.     DO
  141.         l = INSTR(t$, ",")
  142.         IF l = 0 THEN EXIT DO
  143.         count = count + 1
  144.         REDIM _PRESERVE Sun(count) AS Sun_Data_type
  145.         whole$ = LEFT$(t$, l)
  146.         Sun(count).field = LEFT$(whole$, INSTR(whole$, ":") - 1)
  147.         r$ = MID$(whole$, INSTR(whole$, ":") + 1)
  148.         r$ = LEFT$(r$, LEN(r$) - 1)
  149.         IF RIGHT$(r$, 1) = "M" THEN m$ = RIGHT$(r$, 3) ELSE m$ = ""
  150.         h = GetHour(r$) - GetTimeOffset / 60: m = GetMinute(r$): s = GetSecond(r$)
  151.         IF h < 1 THEN h = h + 12 'adjust for AM/PM difference, if ever necessary
  152.         IF h > 12 THEN h = h - 12 'adjust for AM/PM difference, if ever necessary
  153.         Sun(count).value = _TRIM$(STR$(h)) + ":" + _TRIM$(STR$(m)) + ":" + _TRIM$(STR$(s)) + m$
  154.         t$ = MID$(t$, l + 1)
  155.     LOOP
  156.  

Since the plan is to only have this information available on a TODAY basis, and not for any given day, I'm not going to try and detect for what days are modified by daylight savings time, and what aren't.  I'm just going to use the overall modifier that our system gives us, and go with that.  If you need something different, then I'll leave it up to you to sort out when to apply the DST modifier and when not to.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: A quick program for folks to test
« Reply #17 on: December 25, 2020, 07:49:14 am »
seems to work ok
but I would prefer calculating the sunrise/set locally instead of accessing the web, also, I am not fond of using the shell and temporary files
here's code that calculates the sunrise/set https://skyandtelescope.org/wp-content/uploads/sunup.bas
« Last Edit: December 25, 2020, 08:04:51 am by jack »

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: 🎄Re: A quick program for folks to test🎄
« Reply #18 on: December 25, 2020, 10:18:02 am »
So in Australia we have longer Xmas days than you.
Yea, but everything is upside down.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: A quick program for folks to test
« Reply #19 on: December 25, 2020, 10:49:28 am »
I refactored the code
Code: QB64: [Select]
  1. '
  2. '   This program by Roger W. Sinnott calculates the times of sunrise
  3. '   and sunset on any date, accurate to the minute within several
  4. '   centuries of the present.  It correctly describes what happens in the
  5. '   arctic and antarctic regions, where the Sun may not rise or set on
  6. '   a given date.  Enter north latitudes positive, west longitudes
  7. '   negative.  For the time zone, enter the number of hours west of
  8. '   Greenwich (e.g., 5 for EST, 4 for EDT).  The calculation is
  9. '   discussed in Sky & Telescope for August 1994, page 84.
  10.  
  11. Declare Sub FA(Byref X As Single, Byref Y As Single, Byref T As Single)
  12. '        Sunrise-Sunset
  13. '        Constants
  14. DIM A(2) AS SINGLE, D(2) AS SINGLE, DR AS SINGLE, K1 AS SINGLE
  15. P1 = 3.14159265
  16. P2 = 2 * P1
  17. DR = P1 / 180
  18. K1 = 15 * DR * 1.0027379
  19. S1 = "Sunset at  "
  20. R1 = "Sunrise at "
  21. M1 = "No sunrise this date"
  22. M2 = "No sunset this date"
  23. M3s = "Sun down all day"
  24. M4 = "Sun up all day"
  25.  
  26. INPUT "Lat, Long (deg)"; B5, L5
  27. INPUT "Time zone (hrs)"; H
  28. L5 = L5 / 360
  29. Z0 = H / 24
  30. '
  31. '     Calendar --> JD
  32. Y = 2020
  33. M = 12
  34. D3 = 25 'INPUT "Year, Month, Day";Y,M,D3
  35. G = 1
  36. IF Y < 1583 THEN G = 0
  37. D1 = INT(D3)
  38. F = D3 - D1 - .5
  39. J = -INT(7 * (INT((M + 9) / 12) + Y) / 4)
  40. IF G <> 0 THEN
  41.     S = SGN(M - 9)
  42.     A1 = ABS(M - 9)
  43.     J3 = INT(Y + S * INT(A1 / 7))
  44.     J3 = -INT((INT(J3 / 100) + 1) * 3 / 4)
  45. J = J + INT(275 * M / 9) + D1 + G * J3
  46. J = J + 1721027 + 2 * G + 367 * Y
  47. IF F < 0 THEN
  48.     F = F + 1
  49.     J = J - 1
  50. T = (J - 2451545) + F
  51. TT = T / 36525 + 1 ' TT = centuries
  52. '               from 1900.0
  53. '     LST at 0h zone time
  54. T0 = T / 36525
  55. S = 24110.5 + 8640184.813 * T0
  56. S = S + 86636.6 * Z0 + 86400 * L5
  57. S = S / 86400
  58. S = S - INT(S)
  59. T0 = S * 360 * DR
  60. T = T + Z0
  61. '
  62. '       Get Sun's Position
  63. CALL FA(A(1), D(1), T)
  64. T = T + 1
  65. CALL FA(A(2), D(2), T)
  66. IF A(2) < A(1) THEN A(2) = A(2) + P2
  67. Z1 = DR * 90.833 ' Zenith dist.
  68. S = SIN(B5 * DR)
  69. C = COS(B5 * DR)
  70. Z = COS(Z1)
  71. M8 = 0
  72. W8 = 0
  73. A0 = A(1)
  74. D0 = D(1)
  75. DA = A(2) - A(1)
  76. DD = D(2) - D(1)
  77. FOR C0 = 0 TO 23
  78.     P = (C0 + 1) / 24
  79.     A2 = A(1) + P * DA
  80.     D2 = D(1) + P * DD
  81.     '
  82.     '  Test an hour for an event
  83.     L0 = T0 + C0 * K1
  84.     L2 = L0 + K1
  85.     H0 = L0 - A0
  86.     H2 = L2 - A2
  87.     H1 = (H2 + H0) / 2 '  Hour angle,
  88.     D1 = (D2 + D0) / 2 '  declination,
  89.     '                at half hour
  90.     IF C0 <= 0 THEN
  91.         V0 = S * SIN(D0) + C * COS(D0) * COS(H0) - Z
  92.     END IF
  93.     V2 = S * SIN(D2) + C * COS(D2) * COS(H2) - Z
  94.     IF SGN(V0) <> SGN(V2) THEN
  95.         V1 = S * SIN(D1) + C * COS(D1) * COS(H1) - Z
  96.         A1 = 2 * V2 - 4 * V1 + 2 * V0
  97.         B = 4 * V1 - 3 * V0 - V2
  98.         D3 = B * B - 4 * A1 * V0
  99.         IF D3 >= 0 THEN
  100.             D3 = SQR(D3)
  101.             IF V0 < 0 AND V2 > 0 THEN PRINT R1;
  102.             IF V0 < 0 AND V2 > 0 THEN M8 = 1
  103.             IF V0 > 0 AND V2 < 0 THEN PRINT S1;
  104.             IF V0 > 0 AND V2 < 0 THEN W8 = 1
  105.             E = (-B + D3) / (2 * A1)
  106.             IF E > 1 OR E < 0 THEN E = (-B - D3) / (2 * A1)
  107.             T3 = C0 + E + 1 / 120: ' Round off
  108.             H3 = INT(T3)
  109.             M3 = INT((T3 - H3) * 60)
  110.             PRINT USING "##:##"; H3; M3;
  111.             H7 = H0 + E * (H2 - H0)
  112.             N7 = -COS(D1) * SIN(H7)
  113.             D7 = C * SIN(D1) - S * COS(D1) * COS(H7)
  114.             AZ = ATN(N7 / D7) / DR
  115.             IF D7 < 0 THEN AZ = AZ + 180
  116.             IF AZ < 0 THEN AZ = AZ + 360
  117.             IF AZ > 360 THEN AZ = AZ - 360
  118.             PRINT USING ",  azimuth ###.#"; AZ
  119.         END IF
  120.     END IF
  121.     A0 = A2
  122.     D0 = D2
  123.     V0 = V2
  124. '  Special msg?
  125. '
  126. '   Special-message routine
  127. IF M8 <> 0 AND W8 <> 0 THEN
  128.     IF M8 = 0 THEN PRINT M1
  129.     IF W8 = 0 THEN PRINT M2
  130.     IF V2 < 0 THEN PRINT M3s
  131.     IF V2 > 0 THEN PRINT M4
  132. '
  133.  
  134. SUB FA (A5 AS SINGLE, D5 AS SINGLE, T AS SINGLE)
  135.     '   Fundamental arguments
  136.     '     (Van Flandern &
  137.     '     Pulkkinen, 1979)
  138.     DIM P2 AS SINGLE, L AS SINGLE, V AS SINGLE, U AS SINGLE
  139.     DIM W AS SINGLE, S AS SINGLE, R5 AS SINGLE, G AS SINGLE
  140.     DIM TT AS SINGLE
  141.     P2 = 6.283185307179586
  142.     L = .779072 + .00273790931 * T
  143.     G = .993126 + .0027377785 * T
  144.     L = L - INT(L): G = G - INT(G)
  145.     L = L * P2: G = G * P2
  146.     V = .39785 * SIN(L)
  147.     V = V - .01000 * SIN(L - G)
  148.     V = V + .00333 * SIN(L + G)
  149.     V = V - .00021 * TT * SIN(L)
  150.     U = 1 - .03349 * COS(G)
  151.     U = U - .00014 * COS(2 * L)
  152.     U = U + .00008 * COS(L)
  153.     W = -.00010 - .04129 * SIN(2 * L)
  154.     W = W + .03211 * SIN(G)
  155.     W = W + .00104 * SIN(2 * L - G)
  156.     W = W - .00035 * SIN(2 * L + G)
  157.     W = W - .00008 * TT * SIN(G)
  158.     '
  159.     '    Compute Sun's RA and Dec
  160.     S = W / SQR(U - V * V)
  161.     A5 = L + ATN(S / SQR(1 - S * S))
  162.     S = V / SQR(U): D5 = ATN(S / SQR(1 - S * S))
  163.     R5 = 1.00021 * SQR(U)
  164.  

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: A quick program for folks to test
« Reply #20 on: December 26, 2020, 07:36:53 pm »
@Bert22306, @johnno56

Give the following version a run, guys, and see what you get:

. . .

For Bert, I'm hoping that you'll basically run but see a whole lot of nothing, as we should error trap now for non-existent files.  You could always try running it as admin and see if that makes a difference on your work machine, but I imagine it's some sort of system limitation.  Powershell is only available from windows 7 up, so if your enterprise machines don't give proper permissions, or run on an older version of windows, then they're definitely not going to work.  A test just to make certain things fail properly, without crashing, would be nice in this case.  :)

Sorry for the delay in responding. Wife kept me busy for Christmas.

This time, I again got the private IP address behind my NAT, as opposed to the public IP address facing the enterprise. But not much more than that:

"Your latitude and longitude is 0 0

"For your location, the following is true for Christmas day:"

"Press any key to continue"

Of course, with Christmas day having passed, I'm not sure what to expect. But you said it. These corporate machines are pretty tightly locked up. They used to trust me with admin privileges, until this last refresh. No more. I should try it on my own machine, when I get a chance.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: A quick program for folks to test
« Reply #21 on: December 26, 2020, 08:38:30 pm »
Steve,

The 'file not found' went away. But did not display anything. Commented out the first two lines (console) and reran.

See attached for output.

Regards

J

  [ You are not allowed to view this attachment ]  
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A quick program for folks to test
« Reply #22 on: December 26, 2020, 09:00:03 pm »
Steve,

The 'file not found' went away. But did not display anything. Commented out the first two lines (console) and reran.


Does this work from the command line for you:

nslookup myip.opendns.com resolver1.opendns.com

It should give you a couple of lines of information about what your public IP address is.  On windows, we get 4 lines and a blank line.  What's the output look like for Linux?



Second question: Do you have wget installed?  Even if it doesn't find your IP, you should still be able to get sun data for Lat/Long 0, 0.

Make one quick change and test it for me.  In the Download routine, change:

        OUT$ = "wget " + CHR$(34) + link$ + " -O " + file$ + CHR$(34)

To:

        OUT$ = "wget " + CHR$(34) + link$ + CHR$(34) + " -O "+ CHR$(34) + file$ + CHR$(34)

As long as you have wget on your machine, I'm thinking the problem is probably something simple which we might be able to save with quotes in the proper place to deliminate our fields.

Heck, you might even try:

        OUT$ = "wget "  + link$  + " -O " + file$

I'm not on a Linux system, so I can't readily test things for them, but I imagine the glitch here is really something rather simple.  It's not that hard to shell out of wget and have it download a webpage to a file for you.  At least, not usually.  :P
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: A quick program for folks to test
« Reply #23 on: December 27, 2020, 04:34:12 am »
And if all works well, the following version should now make adjustments to the time to account for your local time zone and current daylight saving time.

On my own Win10 PC, this works. Up top, the times (datybreak, llocal noon, etc.) seem to be given in GMT (roughly 5 hours ahead). I'll nit: the top info, before the Christmas Day info, would probably benefit from line breaks.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A quick program for folks to test
« Reply #24 on: December 27, 2020, 05:09:33 am »
On my own Win10 PC, this works. Up top, the times (datybreak, llocal noon, etc.) seem to be given in GMT (roughly 5 hours ahead). I'll nit: the top info, before the Christmas Day info, would probably benefit from line breaks.

Did you try the version at Reply #16?  It should detect your PC's time offset and adjust accordingly for it.  ;)

I'm thinking most of the Windows issues have been sorted out.  Now, if I could only figure out what the heck was wrong with it on Linux for johnno.
« Last Edit: December 27, 2020, 05:12:30 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: A quick program for folks to test
« Reply #25 on: December 29, 2020, 05:08:12 am »
Steve,

Limited success.

  [ You are not allowed to view this attachment ]  

wget was one of the first programs installed when I upgraded the OS.

  [ You are not allowed to view this attachment ]  

Actual location is: -38.0828828   145.281849
Logic is the beginning of wisdom.

Offline zaadstra

  • Newbie
  • Posts: 78
    • View Profile
Re: A quick program for folks to test
« Reply #26 on: January 02, 2021, 11:18:32 am »
Yours won't run, as it relies on window's Powershell to download info from the web.  I'll need to add a Linux method to do the same, and then it'll work for you.

Wget (command line) exists for Windows too - I use it a lot in QB64 to grab a webpage.   If you need to rely on an external program this might be wget, it makes your code a bit more platform independent.

Here is a site with some explanation and a download link to a recent version: https://builtvisible.com/download-your-website-with-wget/