How to check for existence of an URL?

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

mamo
Posts: 205
Joined: Wed Nov 07, 2012 9:11 am

How to check for existence of an URL?

Postby mamo » Tue Jul 31, 2018 12:21 am

Dear Eviewers,

I use Eviews 10+.
Would anybody have a suggestion how to check for the existence of an url?
(for instance: excel file with US GDP data at the BEA, "https://www.bea.gov/national/xls/gdplev.xlsx")
It seems that the Eviews-function "@fileexist" does not work with urls.

Best, mamo

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13603
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to check for existence of an URL?

Postby EViews Gareth » Tue Jul 31, 2018 6:49 am

Try opening it and if it fails, it doesn’t exist?

mamo
Posts: 205
Joined: Wed Nov 07, 2012 9:11 am

Re: How to check for existence of an URL?

Postby mamo » Tue Jul 31, 2018 7:49 am

Well I am looking for sth which can be applied in a program, for instance
%url="https://www.bea.gov/national/xls/gdplev.xlsx"
if @urlexist(%url) then
'do something
else
'do something else
endif

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13603
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to check for existence of an URL?

Postby EViews Gareth » Tue Jul 31, 2018 9:04 am

Code: Select all

setmaxerrs 2 wfopen "https://www.bea.gov/national/xls/gdplev.xlsx" if @errorcount>0 then 'do something else ' do something else endif

mamo
Posts: 205
Joined: Wed Nov 07, 2012 9:11 am

Re: How to check for existence of an URL?

Postby mamo » Wed Aug 01, 2018 3:56 am

Many thanks, this is a workable patch-around.
For completeness and for whom it may be useful, I provide below a subroutine with improved code (disabling also log-messages, and resetting the error counter).
However, this work-around requires reading in the respective file linked to by the url. If the file is large, this wastes considerable computing time.
Hence, I'd like to suggest to the EVIEWS team to consider implementing a more efficient approach in a function named like '@urlexist' in upcoming versions.

mamo

Code: Select all

' %url="http://www.euklems.net/TCB/2017/US_output_17i.xlsx" ' smaller file; routine works reasonably fast %url="https://www.bea.gov/national/xls/gdplev.xlsx" ' large file; routine take a lot of time for a simple check! !checkurl=0 call checkurl(%url, !checkurl) statusline !checkurl subroutine checkurl(string %url, scalar !check) setmaxerrs 2 logmode -e !check=0 wfopen %url if @errorcount=0 then !check=1 wfclose endif clearerrs setmaxerrs 1 logmode 2 endsub


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests