How should I dynamically generate html tables?

Scrumpy reply at in_newsgroup.tks
Sun May 26 14:38:00 EDT 2002


"Mark McEahern" <marklists at mceahern.com> wrote in 
news:mailman.1022369624.25499.python-list at python.org:

> Re: subject
> 
> This essay, written almost 3 years ago by Guido, was very helpful for me:
> 
>   http://www.python.org/doc/essays/ppt/sd99east/
> 
> In particular, check out the faq wizard case study:
> 
> http://www.python.org/doc/essays/ppt/sd99east/sld063.htm
> 
> Cheers,
> 
> // mark

Thanks for your post.

The above presentation appears to provide a small piece of the puzzle i.e. 
about using persistent data stored in "plain files".

I like Guido's comment about storing persistent data "In a real database 
(if you must)" ;-)

When the "plain file" is actually a CSV file, as in my case, and each line 
(record) contains data 'fields', then I need to know how to parse(?) the 
file correctly in order to match each field of a single record to the 
correct location in a HTML table template.

FYI, here is one record from my CSV file. Just pretend it's not wrapped :)

GnuPG,"Encryption .",1.0.6,"Mac, Nix, 
Win32",GPL,690KB,2002/05/10,http://www.gnupg.org/,"GnuPG is a popular 
implementation of OpenPGP http://www.openpgp.org/ . If you want encrypted, 
non-repudiatable (is that a word?!) electronic communications then look no 
further! GUI frontends/plugins have been created for various platforms if 
you balk at using the command-line (or want to increase your productivity!) 
but I suggest that you create your private key directly within GnuPG. After 
reading recent online discussions, I recommend that you generate encryption 
keys not less than 2048 bits."

As per my initial post, I currently perform a MS Word 'catalog mail merge'   
between an RTF file (actually a HTML table) and my CSV file.

Here is the HTML table in question:

<p align="center"><br><a href="#top"><img border="0" 
src="./images/uparrow.gif" alt="" width="20" height="20"></a><br><br></p>

<a name="«CATEGORY»"></a>
<b>   «CATEGORY»</b><br>

<table cellspacing=0 style='width:100%;border-top:solid navy 2px;border-
left:solid navy 2px;
	border-bottom:solid navy 2px;border-right:solid navy 2px;background-
color:#ccffcc;'>
 <tr>
  <td style="width:60%;padding:0px 0px 0px 5px;">
  <span class="redtext">«NAME»</span>
  </td>
  <td style="width:40%;padding:0px 0px 0px 0px;">
  <span class="orangetext">License:</span>
	<span class="datatext"> «LICENSE»</span>
  </td>
 </tr>
 <tr>
  <td colspan=2 style="width:100%;padding:0px 5px 0px 5px"><br>
  <p class=description>«COMMENTS»</p><br>
  </td>
 </tr>
 <tr>
  <td style="width:60%;padding:0px 0px 3px 5px;">
  <span class="orangetext">Website:</span>
	<span class="datatext"> <a href="«WEBSITE»">«WEBSITE»</a></span><br>
	<span class="orangetext">Download Size:</span>
	<span class="datatext"> «SIZE»</span>
  </td>
  <td style="width:40%;padding:0px 0px 3px 0px;">
  <span class="orangetext">Platforms:</span>
	<span class="datatext"> «OS»</span><br>
	<span class="orangetext">Version I Use:</span>
	<span class="datatext"> «VERSION_I_USE»</span><br>
	<span class="orangetext">Record Updated:</span>
	<span class="datatext"> «RECORD_UPDATED»</span>
  </td>
 </tr>
</table>

I then copy the merge's resulting multiple html tables text to my 
freesoft.html file, overwritting the previous right div column's content 
and manually update my software category's menu in the left div column, if 
any categories have been added or deleted. The current page is here:
http://www.geocities.com/scrumpyshangout/freesoft.html

I forsee the process of automatically generating my webpage as something 
like this:

1/ All the top static html down to my left and right div columns can be 
added to a new freesoft.html file.
2/ The CSV file is then parsed and, one by one, each record's data is 
merged with a table and appended to a right div column in the freesoft.html 
file.
3/ During parsing, each record's software "Category" field's data (string) 
is stored in a temp file.
4/ Once all records have been merged, the Category temp file is then 
processed. Duplicated strings are deleted and then a left div column menu 
is generated and appended to the freesoft.html file.
5/ Finally the bottom, static html is appended to, and completes the 
freesoft.html file. THE END ;-)

With my current free Geocities site, I'll have to run the above steps on my 
home PC and then manually upload the freesoft.html to my site.

Finally on my third attempt, I think I've correctly explained what I'm 
trying to achieve. That's if you've read this far! Sorry :)

If anyone can point me in the right direction to be able to complete the 
above process, I'd be very grateful.

For this particular task, do you think I'm best served using Python or PHP? 
I don't mind learning some PHP just for this type of thing if it's easier!

My main aim for the future though is to learn a scripting language to 
create GUI apps, large web apps etc.

Thanks again,
Scrumpy :)



More information about the Python-list mailing list