"Dynamic" website content

S

sophie_newbie

Basically I have written a cgi script to automatically download TIFF
images of patents from the US patent office.

What I want is that the user can see what is happening when the images
are being downloaded, because it takes a while to download them and
there can be anything up to 30 individual files for each image.

Is there a way of using Python or any other means, that I could it
could print on the webpage:

Downloading image 1

Downloading image 2
....
Downloading image X

as the individual pictures are being downloaded so the user doesn't
think the program is hanging?
 
D

Diez B. Roggisch

sophie_newbie said:
Basically I have written a cgi script to automatically download TIFF
images of patents from the US patent office.

What I want is that the user can see what is happening when the images
are being downloaded, because it takes a while to download them and
there can be anything up to 30 individual files for each image.

Is there a way of using Python or any other means, that I could it
could print on the webpage:

Downloading image 1

Downloading image 2
...
Downloading image X

as the individual pictures are being downloaded so the user doesn't
think the program is hanging?

Why? In my browser, if I download a file, the browser itself shows a
nice progress-bar. I guess what you are after is a way to trigger a
download while the current page is displayed in the browser.

Looking at sf, one can see that the header of the site explaining to you
that your download now starts contains this:

<meta http-equiv="refresh" content="5;
URL=http://peterhost.dl.sourceforge.net/sourceforge/winavr/WinAVR-20050214-install.exe"
/>


That means that 5 seconds later, the URL is fetched. As the type is
neither image nor HTML, the browser will download it.

In conclusion, it should even suffice to just let the user click that
link itself. Then the browser should start downloading that image of yours.

Regards,

Diez
 
S

sophie_newbie

To give you a better explaination of what I want, you could visit
www.pat2pdf.org.

Type in 123456 as the patent number, you see what it does? It tells the
user that it is requesting the various TIFF images and then displays
the link to the PDF file that it has created.

This is exactly what I want to do, so if anyone has any idea how it is
done I would be greatful.

I'm not asking how to get the TIFF files of create the PDF etc, that is
grand, just how it updates the screen with its progress like that...
 
D

Diez B. Roggisch

sophie_newbie said:
To give you a better explaination of what I want, you could visit
www.pat2pdf.org.

Type in 123456 as the patent number, you see what it does? It tells the
user that it is requesting the various TIFF images and then displays
the link to the PDF file that it has created.

This is exactly what I want to do, so if anyone has any idea how it is
done I would be greatful.

I'm not asking how to get the TIFF files of create the PDF etc, that is
grand, just how it updates the screen with its progress like that...

It seems that they just fetch the tiff and then write "Fetched
%i<br/>\n" into the page.

The important thing then is to flush the stdout, so that the data is
actually transmitted over the network. And I guess you have to provide a
header that accounts for the number of bytes you want to write (the
total bytes of the html-page that is), by specifying something equals or
maybe greater than the overall page.

Regards,

Diez
 
C

Christoph Haas

To give you a better explaination of what I want, you could visit
www.pat2pdf.org.

Type in 123456 as the patent number, you see what it does? It tells the
user that it is requesting the various TIFF images and then displays
the link to the PDF file that it has created.

Ah, so you are trying to get the page displayed while your CGI is still
running? Try flushing stdout after you print something. Otherwise the
output will only be sent when the CGI ends or the buffer is full.

Kindly
Christoph
 
A

Alex Martelli

Christoph Haas said:
Ah, so you are trying to get the page displayed while your CGI is still
running? Try flushing stdout after you print something. Otherwise the
output will only be sent when the CGI ends or the buffer is full.

....unless you run Python with the -u option, which makes output
unbuffered (and, if on Windows where it matters, binary). However, it's
not sufficient to ensure the user's browser will show the messages you
want when you want. A much more reliable way to achieve that is to use
timed redirects, or an AJAX (Javascript-based) solution.


Alex
 
S

sophie_newbie

Flushing to stdout doesn't seem to work anyway.

Honestly have no idea how you'd implement it in Javascript so might
have an ask on one of their forums...
 
S

sophie_newbie

To be honest that doesn't seem to work. Also it seems that only Mozilla
based browsers support server push.

Maybe it is something to do with how Apache is configured?

Or is Python buffering the output? Is there a line of code to make
python unbeffered?
 
S

sophie_newbie

I am running apache on windows by the way. I think there may be issues
with unbuffered output on windows...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,283
Messages
2,571,405
Members
48,098
Latest member
inno vation

Latest Threads

Top