[Zope] csv -> urllib -> zSQL

Tino Wildenhain tino at wildenhain.de
Fri Aug 27 01:33:45 EDT 2004


Hi,

Am Do, den 26.08.2004 schrieb David Siedband um 23:39:
> I'm trying to read data from a csv on a remote machine and get it into  
> MySQL.
> 
> recordEnergyReading is a zSQL in the same directory as this python  
> script.
> 
> def powerData(self,REQUEST):
>     import csv
>     import urllib
>     inFile =  
> "".join(urllib.urlopen('http://www.davisenergy.com/zeh_data/
> A042304.DAT').readlines())
>     from cStringIO import StringIO
>     filebody=StringIO(inFile.read())
>     reader = csv.DictReader(filebody,("recdate", "recTime", "TAO",  
> "TA1z", "TA2z", "TA1C", "TA2C", "INSOL", "EACz", "EFANz", "EHSEz",  
> "EPV", "GASFz", "DMP", "EAC1c", "EAC2c", "EFAN1", "EFAN2", "EHSEc",  
> "GASFc"))
>     for row in reader:
>      self.recordEnergyReading(row)
> 
> The zSQL works fine when tested on it's own.  How do I locate the  
> problem?

raise NotEnoughContextError()

;-)

well... I think I understand you have a .csv file somewhere on
another server, now you have an external method which is
supposed to fetch the remote file and parse it, right?

Now you want to use the ZSQL method recordEnergyReading()
in the same container as the external method to insert
data. Still getting right?

You did not tell us the errors you get!

My thinking:

the row is like a dictionary? So row 
is something like {"recdate":"01.01.1970", ... } ?
And your ZSQL method uses the keys you wrote above
as parameters?

like:

INSERT INTO blah (recdate, recTime, ...)
VALUES (<dtml-sqlvar recdate type=string>,
<dtml-sqlvar recTime type=string> ... ) 

?

So you just change your call from 

     self.recordEnergyReading(row)

to:
     self.recordEnergyReading(**row)

see your python manual on what this means :-)

Regards
Tino Wildenhain



More information about the Zope mailing list