html code generation

G

George Trojan

I need an advice on table generation. The table is essentially a fifo,
containing about 200 rows. The rows are inserted every few minutes or
so. The simplest solution is to store row data per line and write
directly html code:
line = "<tr><td>value1</td><td>value2>... </tr>"
each run of the program would read the previous table into a list of
lines, insert the first row and drop the last one, taking care of table
header and trailer.
Is there a more classy solution?

George
 
D

D'Arcy J.M. Cain

I need an advice on table generation. The table is essentially a fifo,
containing about 200 rows. The rows are inserted every few minutes or
so. The simplest solution is to store row data per line and write
directly html code:
line = "<tr><td>value1</td><td>value2>... </tr>"
each run of the program would read the previous table into a list of
lines, insert the first row and drop the last one, taking care of table
header and trailer.
Is there a more classy solution?

Almost positively. It's hard to say for sure though without knowing
more. However, I have a few pointers for you.

First, think about a proper database. You can store the raw data into
something like PostgreSQL and then you have your historical record.
Then you can extract and format the latest 200 records at run time. You
can change that value any time you want and even look at historical
information such as the output exactly 24 hours ago.

Whether you generate the page on demand or pre-calculate at intervals
will depend on the ratio of updates to displays. I would start with
generating on demand to start with and profile usage.

Look into server side HTML. It can be a bit ugly generating your
entire web page in code. Write the static part as a regular file and
include your small Python script to generate the table data. The cool
thing with that is that you can give your webaster the task of making
pretty pages and simply deal with the variable generation.

HTH.
 
J

Jon Clements

Almost positively.  It's hard to say for sure though without knowing
more.  However, I have a few pointers for you.

First, think about a proper database.  You can store the raw data into
something like PostgreSQL and then you have your historical record.
Then you can extract and format the latest 200 records at run time.  You
can change that value any time you want and even look at historical
information such as the output exactly 24 hours ago.

Whether you generate the page on demand or pre-calculate at intervals
will depend on the ratio of updates to displays.  I would start with
generating on demand to start with and profile usage.

Look into server side HTML.  It can be a bit ugly generating your
entire web page in code.  Write the static part as a regular file and
include your small Python script to generate the table data.  The cool
thing with that is that you can give your webaster the task of making
pretty pages and simply deal with the variable generation.

HTH.

I'd second this and go for a DB solution; possibly even SQLite to
start with.

I would tend to go with a web framework (maybe OTT) or a templating
engine, so if you wish, someone can do the CSS/HTML and you just
provide something that says (gimme the last 200 hundred rows). Very
similar to what D'Arcy J.M. Cain has said but should hopefully
formalise the possible problem and be applicable across the project.

Further more you might want to look into AJAX, but ummm, that's a
completely new debate :)

Cheers,
Jon.
 
J

John Nagle

George said:
I need an advice on table generation. The table is essentially a fifo,
containing about 200 rows. The rows are inserted every few minutes or
so. The simplest solution is to store row data per line and write
directly html code:
line = "<tr><td>value1</td><td>value2>... </tr>"
each run of the program would read the previous table into a list of
lines, insert the first row and drop the last one, taking care of table
header and trailer.
Is there a more classy solution?

George

The "HTMLTemplate" module is good for simple tasks like that.
There are much more elaborate frameworks available, but if all you
need to do is build a table periodically, it's a simple solution.

This page

http://www.sitetruth.com/reports/phishes.html

is built with HTMLtemplate. It changes only every three hours,
and computing it requires a big SQL join, so it's an automatically
updated static page.

John Nagle
 

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
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top