1. Getting this to Work
- Posted by c.k.lester <euphoric at cklester.com> Apr 01, 2007
- 610 views
Can anybody figure out what's wrong with this code?
without warning include uniquefn.e global function getRSSFeed( sequence url ) sequence result, sys, lines object fname, fn, line atom timer result = "" fname = uniquefn("") sys = "wget -q -b -O " & fname & " -o " & "wget.log " & url fn = system_exec(sys,2) fn = open(fname,"r") timer = time() + 1 while fn = -1 and time() < timer do -- give it a second to open the file fn = open(fname,"r") end while if fn > 0 then -- opened the file lines = "" line = gets(fn) while sequence(line) do lines &= line line = gets(fn) end while close(fn) if length(lines) > 0 then result = "Success from " & fname & ":\n" & lines else result = "Failed to get anything from " & fname & " (fn = " & sprintf("%d",{fn}) & ")" end if else result = "Failed to open file " & fname end if return result end function puts(1,getRSSFeed("http://www.listfilter.com/EUforum/messages.xml"))
The uniquefn.e can be gotten from here: http://cklester.com/euphoria/?snippet=uniquefn.snippet
2. Re: Getting this to Work
- Posted by Leonardo Cecchi <leonardoce at interfree.it> Apr 01, 2007
- 579 views
Hi, I think the problem is that you have the "-b" option in the wget invocation. The fact that wget has successfully created the file doesn't mean that he have already downloaded all the page. I removed the "-b" option from the command line and now it works. In order to give two seconds to wget to download the file i've changed your code like this:
without warning include uniquefn.e constant CLOCK_PER_SEC=10000 global function getRSSFeed( sequence url ) sequence result, sys, lines object fname, fn, line atom timer, delta result = "" fname = uniquefn("") sys = "wget -q -b -O " & fname & " -o " & "wget.log " & url fn = system_exec(sys,2) delta = 2 / CLOCK_PER_SEC timer = time() + delta while time() < timer do -- give it two seconds to open the file -- no op end while fn = open(fname,"r") if fn > 0 then -- opened the file lines = "" line = gets(fn) while sequence(line) do lines &= line line = gets(fn) end while close(fn) if length(lines) > 0 then result = "Success from " & fname & ":\n" & lines else result = "Failed to get anything from " & fname & " (fn = " & sprintf("%d",{fn}) & ")" end if else result = "Failed to open file " & fname end if return result end function puts(1,getRSSFeed("http://www.listfilter.com/EUforum/messages.xml"))
Leonardo
3. Re: Getting this to Work
- Posted by c.k.lester <euphoric at cklester.com> Apr 01, 2007
- 571 views
Leonardo Cecchi wrote: > I think the problem is that you have the "-b" option in the wget invocation. I removed the -b option and it works!!! I think I had just copied what Rob posted recently (news.exu) and assumed that was necessary (it puts wget into the background... whatever that means!). THANKS LEONARDO!!! I owe you a beer or a burger or whatever... :)
4. Re: Getting this to Work
- Posted by Robert Craig <rds at RapidEuphoria.com> Apr 01, 2007
- 564 views
c.k.lester wrote: > Leonardo Cecchi wrote: > > I think the problem is that you have the "-b" option in the wget invocation. > > I removed the -b option and it works!!! I think I had just copied what Rob > posted recently (news.exu) and assumed that was necessary (it puts wget into > the background... whatever that means!). The -b option causes wget to run as an independent process, so your program is not blocked waiting for the download to complete (or a time-out to occur). If your program has nothing better to do than wait, then you shouldn't use -b. You may have had trouble with -b because you can't predict when the file will be created, or when it will contain more than zero bytes. Either event could take a few seconds or more. gets() may report EOF, but if you try it again, gets() might pick up something. It's not really clear when you can assume it's the final, official EOF, unless maybe you know what the last part of the file is supposed to look like, or you assume it must be all done after a certain period of time. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
5. Re: Getting this to Work
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Apr 02, 2007
- 555 views
c.k.lester wrote: > > Can anybody figure out what's wrong with this code? <snip> > }}} <eucode> > sys = "wget -q -b -O " & fname & " -o " & "wget.log " & url > </eucode> {{{ You TRAITOR! All that effort I put into pFinet.ew, for you... OK, only joshing (and I read it was the -b that knobbled you). However why not at least try to do this in pure Eu code? Regards, Pete PS any progress on that Edita/FTP design note?
6. Re: Getting this to Work
- Posted by c.k.lester <euphoric at cklester.com> Apr 02, 2007
- 563 views
Pete Lomax wrote: > c.k.lester wrote: > > Can anybody figure out what's wrong with this code? > <snip> > > }}} <eucode> > > sys = "wget -q -b -O " & fname & " -o " & "wget.log " & url > > </eucode> {{{ > You TRAITOR! All that effort I put into pFinet.ew, for you... > OK, only joshing (and I read it was the -b that knobbled you). > However why not at least try to do this in pure Eu code? I didn't know!!! I'd LOVE to have it be pure Eu code. Tell me about it. :)
7. Re: Getting this to Work
- Posted by c.k.lester <euphoric at cklester.com> Apr 02, 2007
- 574 views
c.k.lester wrote: > Pete Lomax wrote: > > c.k.lester wrote: > > > Can anybody figure out what's wrong with this code? > > <snip> > > > }}} <eucode> > > > sys = "wget -q -b -O " & fname & " -o " & "wget.log " & url > > > </eucode> {{{ > > You TRAITOR! All that effort I put into pFinet.ew, for you... > > OK, only joshing (and I read it was the -b that knobbled you). > > However why not at least try to do this in pure Eu code? > > I didn't know!!! I'd LOVE to have it be pure Eu code. Tell me about it. :) Oh, while you're at it, I need an XML -> HTML proggie, too. Thanks in advance. 8)
8. Re: Getting this to Work
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Apr 02, 2007
- 552 views
c.k.lester wrote: > I didn't know!!! I'd LOVE to have it be pure Eu code. Tell me about it. :) Well I have to recommend Fabio Ramirez's EInetLib.ew, on which my efforts (pretty much the same only more Edita/Arwen-biased) are made. http://www.rapideuphoria.com/cgi-bin/asearch.exu?win=on&keywords=Ramirez http://palacebuilders.pwp.blueyonder.co.uk/pftp.htm mind you, is there nothing in wxEuphoria? Regards, Pete
9. Re: Getting this to Work
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Apr 02, 2007
- 553 views
Pete Lomax wrote: > > c.k.lester wrote: > > I didn't know!!! I'd LOVE to have it be pure Eu code. Tell me about it. :) > > Well I have to recommend Fabio Ramirez's EInetLib.ew, on which my efforts > (pretty > much the same only more Edita/Arwen-biased) are made. > > mind you, is there nothing in wxEuphoria? Yes, wxEuphoria can grab a file off the net. I was using it before Rob actually started offering rss to see what was required to do so. Matta
10. Re: Getting this to Work
- Posted by c.k.lester <euphoric at cklester.com> Apr 02, 2007
- 569 views
Pete Lomax wrote: > > mind you, is there nothing in wxEuphoria? Don't want to use the library for a CGI app.
11. Re: Getting this to Work
- Posted by c.k.lester <euphoric at cklester.com> Apr 02, 2007
- 547 views
Pete Lomax wrote: > > Well I have to recommend Fabio Ramirez's EInetLib.ew, on which my efforts > (pretty > much the same only more Edita/Arwen-biased) are made. BTW, my current method is x-plat. Is EInetLib?
12. Re: Getting this to Work
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Apr 02, 2007
- 548 views
c.k.lester wrote: > my current method is x-plat. Is EInetLib? No, windows only. OK you are officially forgiven for using wget Regards, Pete
13. Re: Getting this to Work
- Posted by Jason Gade <jaygade at yahoo.com> Apr 02, 2007
- 574 views
Matt Lewis wrote: > > Pete Lomax wrote: > > > > c.k.lester wrote: > > > I didn't know!!! I'd LOVE to have it be pure Eu code. Tell me about it. :) > > > > Well I have to recommend Fabio Ramirez's EInetLib.ew, on which my efforts > > (pretty > > much the same only more Edita/Arwen-biased) are made. > > > > mind you, is there nothing in wxEuphoria? > > Yes, wxEuphoria can grab a file off the net. I was using it before Rob > actually started offering rss to see what was required to do so. > > Matta I've still got a demo of this if you want it... I don't know if you've added it to your wxEuphoria example programs or not.
without warning include wxEuphoria.e include wxText.e include wxButton.e include wxNet.e global constant main = create( wxFrame, {0, -1, "Download Demo", 0, 0, 419, 200, wxDEFAULT_FRAME_STYLE }), panel = create( wxPanel, main ), file_label = create( wxStaticText, {panel, -1, "File name:", 13, 34, 116, 22 }), file_name = create( wxTextCtrl, {panel, -1, "http://www.rapideuphoria.com/index.html", 135, 34, 300, 23 }), download_button = create( wxButton, {panel, -1, "Download Now", 13, 126, 96, 30 }) procedure on_click( atom this, atom event_type, atom id, atom event ) atom wxurl, stream integer fn, ix sequence url, current, path url = get_text_value( file_name ) path = reverse( url ) ix = find( '/', path ) if ix then path = reverse( path[1..ix-1] ) else path = reverse( path ) end if wxurl = create( wxURL, url ) stream = get_url_input( wxurl ) if stream then fn = open( path, "wb" ) if fn = -1 then puts(2, "Could not open file!\n" ) else current = stream_read( stream ) puts( fn, current ) delete_instance( stream ) close(fn) end if else puts(2, "Stream failed!\n") end if delete_instance( wxurl ) end procedure set_event_handler( download_button, -1, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("on_click")) wxMain( main )
-- "Any programming problem can be solved by adding a level of indirection." --anonymous "Any performance problem can be solved by removing a level of indirection." --M. Haertel "Premature optimization is the root of all evil in programming." --C.A.R. Hoare j.
14. Re: Getting this to Work
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Apr 02, 2007
- 573 views
Jason Gade wrote: > > I've still got a demo of this if you want it... I don't know if you've added > it to your wxEuphoria example programs or not. > Cool. Here's an update for v0.10.0 (you'll probably need the latest from svn for this to work well at all).
without warning include wxeud.e global constant main = create( wxFrame, {0, -1, "Download Demo", 0, 0, 419, 200, wxDEFAULT_FRAME_STYLE }), panel = create( wxPanel, main ), file_label = create( wxStaticText, {panel, -1, "File name:", 13, 34, 116, 22 }), file_name = create( wxTextCtrl, {panel, -1, "http://wxeuphoria.sourceforge.net", 135, 34, 300, 23 }), download_button = create( wxButton, {panel, -1, "Download Now", 13, 126, 96, 30 }), html_win = create( wxHtmlWindow, {panel, -1}), status_bar = create( wxStatusBar, {main}), vsizer = create( wxBoxSizer, wxVERTICAL ), hsizer = create( wxBoxSizer, wxHORIZONTAL) add_window_to_sizer( hsizer, file_label, 0, 0, 0 ) add_window_to_sizer( hsizer, file_name, 1, 0, 0 ) add_sizer_to_sizer ( vsizer, hsizer, 0, wxGROW + wxTOP + wxLEFT, 10 ) add_window_to_sizer( vsizer, download_button, 0, 0, 0 ) add_window_to_sizer( vsizer, html_win, 1, wxGROW, 0 ) set_sizer( panel, vsizer ) set_related_frame( html_win, main, "%s", 0 ) procedure on_click( atom this, atom event_type, atom id, atom event ) atom wxurl, stream integer fn, ix sequence url, current, path url = get_text_value( file_name ) path = reverse( url ) ix = find( '/', path ) if ix then path = reverse( path[1..ix-1] ) else path = reverse( path ) end if wxurl = create( wxURL, {url} ) stream = get_url_input( wxurl ) if stream then set_html_page( html_win, stream_read( stream ) ) else puts(2, "Stream failed!\n") end if delete_instance( wxurl ) end procedure set_event_handler( download_button, -1, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("on_click")) wxMain( main )
15. Re: Getting this to Work
- Posted by Jason Gade <jaygade at yahoo.com> Apr 02, 2007
- 589 views
Thanks, Matt. I haven't even figured out subversion or cvs or any of those other things yet. I'm not really developing anything at the moment but I will need to continue with my shootout project eventually, and will have to learn those. I'll copy this code for future reference. -- "Any programming problem can be solved by adding a level of indirection." --anonymous "Any performance problem can be solved by removing a level of indirection." --M. Haertel "Premature optimization is the root of all evil in programming." --C.A.R. Hoare j.