Dick Moores | 1 Mar 2008 01:15

Re: How to open IE7 to a certain URL?

At 03:13 PM 2/29/2008, Dick Moores wrote:
At 02:09 PM 2/29/2008, János Juhász wrote:

>
>import time
>b = '20:00:00'
>
>(bhour, bmin, bsec) = b.split(':')
>bsec = int(bsec) + int(bmin)*60 + int(bhour)*360
>
>while True:
>     act = time.localtime()
>     actsec = act.tm_sec + act.tm_min*60 + act.tm_hour*360
>     wait = bsec - actsec
>     if wait < 0:
>         wait += 360*24 # it will be tomorrow
>     time.sleep(wait)
>     print 'I am doing!'
>     break

Ah, very nice! (But all the '360's should be '3600', of course.)

Also, there's no longer any need for the loop.

So:
=========================================
#!/usr/bin/env python
#coding=utf-8
# KCTS.py

import time, os
timeStart = raw_input("Enter starting time as hh:mm:ss ")
if timeStart == "":
    timeStart = "19:59:25"
print "starting time set as", timeStart

b = timeStart

(bhour, bmin, bsec) = b.split(':')
bsec = int(bsec) + int(bmin)*60 + int(bhour)*3600

act = time.localtime()
actsec = act.tm_sec + act.tm_min*60 + act.tm_hour*3600
wait = bsec - actsec
if wait < 0: # startTime is in next day
    wait += 3600*24
print "wait is", wait
time.sleep(wait)
print 'Starting now'
os.startfile('http://www.kuow.org/real.ram')
=================================================

I wish I knew how to change that last line so that it would do what
"E:\Programs\Real Player\realplay.exe" http://www.kuow.org/real.ram
does at the command line--open Real Player at KUOW without calling my browser.

Dick Moores



_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Tiger12506 | 1 Mar 2008 01:25

Re: How to open IE7 to a certain URL?

time.sleep is not exactly accurate, so I would suggest that you use this 
method, short 5 minutes or so and then do a sleep(10) or so in a loop to get 
closer to the time.

>>import time
>>b = '20:00:00'
>>
>>(bhour, bmin, bsec) = b.split(':')
>>bsec = int(bsec) + int(bmin)*60 + int(bhour)*360
>>
>>while True:
>>     act = time.localtime()
>>     actsec = act.tm_sec + act.tm_min*60 + act.tm_hour*360
>>     wait = bsec - actsec
>>     if wait < 0:
>>         wait += 360*24 # it will be tomorrow
>>     time.sleep(wait)
>>     print 'I am doing!'
>>     break
>
> Ah, very nice! (But all the '360's should be '3600', of course.)
>
> Thanks, Janos.
>
> Dick
>
>
> _______________________________________________
> Tutor maillist  -  Tutor <at> python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Chris Fuller | 1 Mar 2008 01:48

Re: How to open IE7 to a certain URL?

On Friday 29 February 2008 18:25, Tiger12506 wrote:
> time.sleep is not exactly accurate, so I would suggest that you use this
> method, short 5 minutes or so and then do a sleep(10) or so in a loop to
> get closer to the time.

Another advantage to shorter sleeps is it reduces the latency of anything else 
your program needs to do, such as exit gracefully, reschedule the event, or 
whatever.  Not too short, because that uses more CPU time.

It also makes a difference if the clock gets reset :)

Cheers
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Chris Fuller | 1 Mar 2008 01:33

Re: How to open IE7 to a certain URL?


I left out the daily increment. there should be a event_time += 86400  end of 
the inner loop.

while True:
   while time()<event_time and not quit():
      sleep(5)

   if quit():
      break

   launch()
   event_time += 86400
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Chris Fuller | 1 Mar 2008 01:11

Re: How to open IE7 to a certain URL?

On Friday 29 February 2008 12:24, Dick Moores wrote:
>  http://www.kuow.org/real.ram .

Try this to start, then turn into a service with FireDaemon, 
http://www.firedaemon.com/.  You'll need to fill in the quit() function, and 
the particulars for your media player.

from time import mktime, strftime, strptime, localtime, time, sleep

# return true if the program should exit
def quit():
   pass

import subprocess
def launch():
   args = ( 'c:\\pathto\\cmd', 'http://www.kuow.org/real.ram' )
   subprocess.call(args)

# get the seconds since epoch of midnight, add the desired time of day,
# and convert back into seconds since epoch. We'll wake up just a bit
# early, so we can use a coarser timer.

event_time = mktime(strptime(strftime('%Y%m%d',
   localtime(time()))+'19:59:40','%Y%m%d%H:%M:%S'))

while True:
   while time()<event_time and not quit():
      sleep(5)

   if quit():
      break

   launch()

Cheers
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

govind goyal | 1 Mar 2008 06:23
Picon

serial -->file tranfer

Hello,

I have a modem connect to my Windows XP PC through a serial cable.
I Want to transfer the file(e.g '.TXT' format) from XP PC to serial modem and also
from Serial modem to winXP PC.

Can anybody help me out how to do it in Python and provide some sample code or useful links
so that I can proceed further in my project??

All help will be highly appreciated.

Thanks & Regards,
Govind

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Kent Johnson | 1 Mar 2008 14:01
Gravatar

Re: serial -->file tranfer

govind goyal wrote:
> Hello,
> 
> I have a modem connect to my Windows XP PC through a serial cable.
> I Want to transfer the file(e.g '.TXT' format) from XP PC to serial 
> modem and also
> from Serial modem to winXP PC.
> 
> Can anybody help me out how to do it in Python and provide some sample 
> code or useful links
> so that I can proceed further in my project??

http://pyserial.sourceforge.net/

The enhancedserial example looks pretty close to what you need:
http://pyserial.cvs.sourceforge.net/pyserial/pyserial/examples/enhancedserial.py?revision=1.1&view=markup

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Ricardo Aráoz | 1 Mar 2008 17:15
Picon

Re: comparison bug in python (or do I not get it?)

Hans Fangohr wrote:
> Hi Kent,
> 
>> Hans Fangohr wrote:
>>
>>> In [2]: 2 in [1,2,3] == True
>>> Out[2]: False
>>>
>>> Why does [2] return False? Would people agree that this is a bug?
>> No, not a bug. Don't be too quick to blame your tools!
> 
> That's good news. I'd be worried if this wasn't the desired behaviour
> -- I just hadn't understood the logic.
> 
>> The equivalent expression is
>> In [1]: (2 in [1,2,3]) and ([1,2,3]==False)
>> Out[1]: False
> 
> Ah -- that's the way to read it!
> 
>> 'in' is considered a comparison operator and can be chained with other
>> comparisons. For a clearer example, consider
>> In [2]: 2 < 3 < 4
>> Out[2]: True
>>
>> which is not the same as
>> In [3]: 2 < (3 < 4)
>> Out[3]: False
>>
>> or
>> In [4]: (2 < 3) < 4
>> Out[4]: True
>>
>> It is equivalent to
>> In [5]: (2 < 3) and (3 < 4)
>> Out[5]: True
>>
> 
> Well explained -- makes perfect sense now.
> 

Just one further question :

 >>> 1 == True
True
 >>> 5 == True
False

and yet

 >>> if 5 : print 'True'
True

I thought a non-zero or non-empty was evaluated as True. Now in the 5 == 
True line I'm not saying "5 is True", shouldn't it evaluate just like 
the "if" statement?

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kent Johnson | 1 Mar 2008 16:41
Gravatar

Re: Need help with encoder & decryption keys

Trey Keown wrote:

> mmm... So, what would be an effective way to hide the data's key?
> I'm kind of new to the whole encryption scene, although I've had some
> experience with it whilst working on homebrew software on gaming
> platforms.

I don't know, I'm not a crypto expert. I guess it depends partly on what 
you are trying to do.

I do have a little experience with SSH, it stores keys in files in the 
filesystem and relies on the OS to protect them from unauthorized access.

Kent

PS Please use Reply All to reply to the list.
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kent Johnson | 1 Mar 2008 16:39
Gravatar

Re: comparison bug in python (or do I not get it?)

Ricardo Aráoz wrote:
>  >>> 1 == True
> True

Yes, True is an integer with value 1. Actually True is a bool but bool 
is a subclass of int:
In [3]: type(True)
Out[3]: <type 'bool'>
In [4]: isinstance(True, int)
Out[4]: True
In [5]: int(True)
Out[5]: 1

>  >>> 5 == True
> False

Right, because 5 != 1

> and yet
> 
>  >>> if 5 : print 'True'
> True
> 
> 
> I thought a non-zero or non-empty was evaluated as True.

Yes, in a boolean context 5 is evaluated as True:
In [7]: bool(5)
Out[7]: True

 From the docs:
In the context of Boolean operations, and also when expressions are used 
by control flow statements, the following values are interpreted as 
false: False, None, numeric zero of all types, and empty strings and 
containers (including strings, tuples, lists, dictionaries, sets and 
frozensets). All other values are interpreted as true.
http://docs.python.org/ref/Booleans.html#Booleans

  Now in the 5 ==
> True line I'm not saying "5 is True", shouldn't it evaluate just like 
> the "if" statement?

No. When you say
   if 5:
you are implicitly converting 5 to a boolean and the 'non-zero evaluates 
to True' rule applies. When you say
   if 5 == True:
you are explicitly comparing the two values and 5 is not converted to 
boolean.

 From the docs:
The operators <, >, ==, >=, <=, and != compare the values of two 
objects. The objects need not have the same type. If both are numbers, 
they are converted to a common type.
http://docs.python.org/ref/comparisons.html

The first one is equivalent to
   if bool(5):
while the second one is
   if 5 == int(True):

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane