html code generation

D'Arcy J.M. Cain darcy at druid.net
Wed Jan 20 23:03:42 CET 2010


On Wed, 20 Jan 2010 21:03:10 +0000
George Trojan <george.trojan at noaa.gov> wrote:
> 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.

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list