Author Topic: Downloading TEXT file from internet  (Read 6661 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline IronMan

  • Newbie
  • Posts: 38
    • View Profile
Downloading TEXT file from internet
« on: March 20, 2020, 08:56:50 pm »
I am obtaining several text files from the NOAA weather site. I'm currently using curl from a shell command from within my QB64 app like:

SHELL "curl https://tgftp.nws.noaa.gov/data/forecasts/zone/ms/msz024.txt >forecast.txt"

to obtain a text file from this site. I however would like to do this within the QB64 itself rather than having to SHELL and run a external application like Curl to fetch the file. I know there is a Download command in QB64, but I'm not understanding how to use it. Does anyone have experience on how to do this? Perhaps a small piece of code for an example?

Any help is appreciated.

Thank you.
Kent

Offline Real2Two

  • Newbie
  • Posts: 18
    • View Profile
Re: Downloading TEXT file from internet
« Reply #1 on: March 20, 2020, 09:00:16 pm »
Try doing some get of GET request of QB64, which I remember seeing code with the GET with QB64, but I forgot about it.

Offline Real2Two

  • Newbie
  • Posts: 18
    • View Profile
Re: Downloading TEXT file from internet
« Reply #2 on: March 20, 2020, 09:02:54 pm »

FellippeHeitor

  • Guest
Re: Downloading TEXT file from internet
« Reply #3 on: March 20, 2020, 09:47:03 pm »
QB64 won’t fetch from an https address.

Offline IronMan

  • Newbie
  • Posts: 38
    • View Profile
Re: Downloading TEXT file from internet
« Reply #4 on: March 20, 2020, 09:54:06 pm »
QB64 won’t fetch from an https address.


Ahhh, didn't know that.

But it will a non-secure FTP or HTTP? I am downloading some images form within QB64 but they're coming off a FTP server.
That must be why I'm having problems when trying to get filed form SSL sites.

Marked as best answer by IronMan on March 20, 2020, 06:50:00 pm

Offline lawsonm1

  • Newbie
  • Posts: 64
    • View Profile
Re: Downloading TEXT file from internet
« Reply #5 on: March 20, 2020, 10:06:10 pm »
I posted a similar question back on 2/6/2020 (Pulling data from a website) https://www.qb64.org/forum/index.php?topic=2158.msg114021#msg114021. wGet was one of the suggestions. That worked out great for what I was doing. I grabbed the website data I wanted, and just parsed out the parts I needed. Mike

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Downloading TEXT file from internet
« Reply #6 on: March 21, 2020, 04:25:34 am »
This posting is for those finding this thread looking for information about using cURL to download files.

Using curl to automate HTTP jobs
https://curl.haxx.se/docs/httpscripting.html

libcurl - the multiprotocol file transfer library
https://curl.haxx.se/libcurl/

Everything curl - the book
https://curl.haxx.se/book.html



Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Downloading TEXT file from internet
« Reply #7 on: March 21, 2020, 04:29:16 am »
And here is the manual for Wget

GNU Wget 1.20 Manual
https://www.gnu.org/software/wget/manual/wget.html

Offline IronMan

  • Newbie
  • Posts: 38
    • View Profile
Re: Downloading TEXT file from internet
« Reply #8 on: March 21, 2020, 05:48:51 pm »
Curl is doing exactly what I need since you can't download files from HTTPS sites in QB64.

Example:
SHELL "curl -k https://tgftp.nws.noaa.gov/data/forecasts/zone/ms/msz024.txt > forecast.txt"

The only thing is, when the SHELL is executed in the program, it opens a black command windows and shows the Curl being ran in it. This is especially isn't good when using inForm in a Windows environment.

Does anyone know if there is a way to not allow the command windows to be shown when SHELL is used?

Thank you.
Kent

FellippeHeitor

  • Guest
Re: Downloading TEXT file from internet
« Reply #9 on: March 21, 2020, 06:19:44 pm »
Code: QB64: [Select]
  1. SHELL _HIDE "curl -k https://tgftp.nws.noaa.gov/data/forecasts/zone/ms/msz024.txt > forecast.txt"
  2.  

Offline IronMan

  • Newbie
  • Posts: 38
    • View Profile
Re: Downloading TEXT file from internet
« Reply #10 on: March 21, 2020, 06:56:22 pm »
Code: QB64: [Select]
  1. SHELL _HIDE "curl -k https://tgftp.nws.noaa.gov/data/forecasts/zone/ms/msz024.txt > forecast.txt"
  2.  

That got it.

Thanks

Offline IronMan

  • Newbie
  • Posts: 38
    • View Profile
Re: Downloading TEXT file from internet
« Reply #11 on: March 21, 2020, 10:12:07 pm »
Code: QB64: [Select]
  1. SHELL _HIDE "curl -k https://tgftp.nws.noaa.gov/data/forecasts/zone/ms/msz024.txt > forecast.txt"
  2.  

The SHELL _HIDE fixed the command window from showing up. I'm now getting a "Please Wait" showing up while the application is after about 3-4 seconds once it starts. Not really causing a problem, but I can't find this anywhere in the code so I assume it's in the inForm code somewhere. Any way to avoid this?

FellippeHeitor

  • Guest
Re: Downloading TEXT file from internet
« Reply #12 on: March 21, 2020, 10:20:30 pm »
InForm will show that when execution is halted for too long. It’ll happen when a SHELL call takes too long or when you do a loop somewhere that hogs the input routines. It is by design.

You cannot disable it, but you can set a custom message:

Code: QB64: [Select]
  1.  __UI_WaitMessage = "Fetching data"

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Downloading TEXT file from internet
« Reply #13 on: March 21, 2020, 11:10:11 pm »
Here's another method without using SHELL.  Just thought I'd throw it into the mix!  Works for me in Windows 7.  Download from https sites. Uses a built-in Windows Library function.   

- Dav

Code: QB64: [Select]
  1.     FUNCTION URLDownloadToFileA% (BYVAL pCaller AS LONG, szURL AS STRING, szFileName AS STRING, BYVAL dwReserved AS LONG, BYVAL lpfnCB AS LONG)
  2.  
  3. url$ = "https://tgftp.nws.noaa.gov/data/forecasts/zone/ms/msz024.txt"
  4. urlfile$ = "forecast.txt"
  5.  
  6. a% = URLDownloadToFileA%(0, url$, urlfile$, 0, 0)
  7.  
  8. SLEEP 5   'pause to allow the download to complete
  9.  
  10. IF a% = 0 THEN
  11.     PRINT "Downloaded!"
  12.     PRINT "NOT Downloaded!"
  13.  

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Downloading TEXT file from internet
« Reply #14 on: March 21, 2020, 11:44:25 pm »
Here's another method without using SHELL.  Just thought I'd throw it into the mix!  Works for me in Windows 7.  Download from https sites. Uses a built-in Windows Library function.   

Dav, the code snippets you post are always great, and this one is no exception. Added to my tool bag. Thank you.
In order to understand recursion, one must first understand recursion.