[Tutor] iterate over daterange

2006-01-06 Thread captnswing
Hello
I have a startdate and an enddate and I want to iterate over all days  
in between the two

 there doesn't seem to be a range function for dates?!?

i.e. currently I am going through integers with something like this:

=
startdate = datetime.date(2006,1,1)
enddate = datetime.date(2006,10,19)

for i in range((enddate-startdate).days + 1):
currentdate = startdate + datetime.timedelta(days=i)

=

this seems so 'unpythonic', there surely must be a better way, no?
thx,
-frank

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] logging to a database

2005-11-12 Thread captnswing
thanks kent,
I actually got it working!
-frank

On 11 nov 2005, at 12.26, Kent Johnson wrote:

> captnswing wrote:
>> Hello all,
>> I would like to log messages to a database (mysql)
>> I found the example log_test14.py that comes with python logging
>> module http://www.red-dove.com/python_logging.html
>> but that example is a bit greek for me ... :) and it doesnt work with
>> mysql
>
> Have you used mysql from Python before? I looked at that example  
> and it is not that complex if you understand how to program a  
> database. I think what you have to do is
>
> - install MySQL and create the database table that you want to log  
> to. The SQL statement in the example shows the fields you might  
> want, or you can use a subset of those fields if you don't need so  
> much information.
>
> - modify the example program a little:
> change
>   import mx.ODBC.Windows
> to the correct import for the MySQL driver
>
> change
>   self.conn = mx.ODBC.Windows.connect(self.dsn, self.uid, self.pwd)
> to the correct statement to connect to MySQL
>
> change the SQL statement to correspond to your database schema
>
>
> If you *haven't* used MySQL from Python before, you should probably  
> learn a little about the basics first.
>
> BTW the example is vulnerable to SQL injection attacks - if any of  
> the log messages contain text from user input you should fix that.  
> But get it working first, then come back and ask for help again.
>
> Kent
>
> -- 
> http://www.kentsjohnson.com
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ftp transfer - queue & retry pattern

2005-11-12 Thread captnswing
Hello,
I want to write a module that transfers a given file to a given  
destination with a given protocol (ftp, sftp, scp)
to start out, just ftp would be sufficient
the destination machines are sometimes unavailable, or the transfer  
fails sometimes due to connection problems

I have several questions (sorry):
1) python ftplib or curl via commands.getoutput(...)? what are the  
benefits / drawbacks (portability is not an issue for me, and I like  
curl a lot)
2) Is there a simple way to create a subprocess(?) that I can  
dispatch my transfer jobs to from my main script.
 The goal is that my main script can proceed without beeing hung  
by the transfer process
3) that subprocess would need a queue, that collects all transfer  
jobs. can you give me some hints on how that could be done in python
4) the subprocess (?) would try to transfer all jobs one after another
 if one transfer fails, retry after a certain time period (say  
2, 5, 10, 20, 40 min) and stop after maxnum retries
how could I code this nicely in python without resorting to if  
then else etc?

or is there a module that does 1)-4) out there somewhere already?
thanks for any insight you might have
-frank

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] logging to a database

2005-11-10 Thread captnswing
Hello all,
I would like to log messages to a database (mysql)
I found the example log_test14.py that comes with python logging  
module http://www.red-dove.com/python_logging.html
but that example is a bit greek for me ... :) and it doesnt work with  
mysql
is there some kind of tutorial how to get going if you want to log to  
a database?
thanks,
-frank

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor