Re: How can I make a program automatically run once per day?

2011-07-27 Thread Chris Angelico
On Wed, Jul 27, 2011 at 2:09 PM, John Salerno johnj...@gmail.com wrote:
 Thank you. I changed it as suggested so that now it runs C:
 \Python32\python.exe extract_songs.py but it still isn't working.

Have you confirmed that the job's working directory is set correctly?
Naming the script without a path depends on the task being run from
the script's directory.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-27 Thread baloan
On Jul 14, 7:00 pm, monkeys paw mon...@joemoney.net wrote:
 On 7/9/2011 10:01 PM, John Salerno wrote:

  Thanks everyone! I probably should have said something like Python,
  if possible and efficient, otherwise any other method ! :)

  I'll look into the Task Scheduler. Thanks again!

 You could use the below code. time.sleep(# seconds in a day)
 where i == 30 would run once a day for a month

 import time
 i=0
 while (1):
         print 'hello'
         time.sleep(2)   # Change this to number of seconds in a day
         if (i == 3):    # make this 30 for a month
                 break
         i = i + 1

This looks like a bad idea to me: to make it work throughout the year
you need to adjust for daylight savings start and end; this is where a
day does not have 24 hours - and, of course, daylight savings depends
on country settings of your host system...

Andreas
bal...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-27 Thread Dave Angel

On 01/-10/-28163 02:59 PM, John Salerno wrote:

On Jul 26, 9:22 pm, Andrew Bergbahamutzero8...@gmail.com  wrote:

On 2011.07.26 08:05 PM,JohnSalernowrote:  Hmm, okay I'm finally trying Task 
Scheduler, but how do I set it to

run a Python script? It seems to not work, I suppose because it's
running the script but doesn't know how to find Python to run it
properly.

Tell it to run the Python interpreter and pass the script as an argument.

--
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB

Thank you. I changed it as suggested so that now it runs C:
\Python32\python.exe extract_songs.py but it still isn't working. A
DOS prompt flashes real quick as it runs, but when I check the output
file that is supposed to be written to, nothing new has been added.
I'm not sure what the problem is now. I know the script itself works
because I just ran it manually and the output was fine.

As Chris pointed out, you probably aren't getting the script's directory 
right.  After all, how can the scheduler guess where you put it?  The 
obvious answer is to use a full path for the script's filename.  Another 
alternative is to fill in the current directory in the appropriate field 
of the scheduler's entry.


I find it useful to only add batch files to the scheduler.  Those batch 
files can do any setup and cleanup necessary.  In this case, the batch 
file might simply set the current directory to the location of the 
script. But it can also pause at the end, so you can read the console 
before it disappears.   Or it could create another file, so you could 
check the timestamp to figure out when it was triggered.


DaveA

--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-27 Thread Chris Angelico
On Wed, Jul 27, 2011 at 10:27 PM, Dave Angel da...@ieee.org wrote:
 As Chris pointed out, you probably aren't getting the script's directory
 right.  After all, how can the scheduler guess where you put it?  The
 obvious answer is to use a full path for the script's filename.  Another
 alternative is to fill in the current directory in the appropriate field of
 the scheduler's entry.

I would prefer setting the current directory, as that allows the
script to find any data files it needs, but either works.

 I find it useful to only add batch files to the scheduler.  Those batch
 files can do any setup and cleanup necessary.  In this case, the batch file
 might simply set the current directory to the location of the script.

And that is an excellent idea. Definitely recommended.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-27 Thread Billy Mays

On 07/27/2011 08:35 AM, Chris Angelico wrote:

On Wed, Jul 27, 2011 at 10:27 PM, Dave Angelda...@ieee.org  wrote:

As Chris pointed out, you probably aren't getting the script's directory
right.  After all, how can the scheduler guess where you put it?  The
obvious answer is to use a full path for the script's filename.  Another
alternative is to fill in the current directory in the appropriate field of
the scheduler's entry.


I would prefer setting the current directory, as that allows the
script to find any data files it needs, but either works.


I find it useful to only add batch files to the scheduler.  Those batch
files can do any setup and cleanup necessary.  In this case, the batch file
might simply set the current directory to the location of the script.


And that is an excellent idea. Definitely recommended.

ChrisA


If it hasn't been mentioned already:

import time

while True:
t1 = time.time()

#your code here

t2 = time.time()
time.sleep( 86400 - (t2 - t1) )



This doesn't take into account leap seconds, but it doesn't depend on a 
task scheduler.  It is also independent of the time your code takes to 
execute.


This is simpler, but it might drift slightly over time.

--
Bill
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-27 Thread John Salerno
On Jul 27, 7:58 am, Billy Mays
81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com wrote:
 On 07/27/2011 08:35 AM, Chris Angelico wrote:









  On Wed, Jul 27, 2011 at 10:27 PM, Dave Angelda...@ieee.org  wrote:
  As Chris pointed out, you probably aren't getting the script's directory
  right.  After all, how can the scheduler guess where you put it?  The
  obvious answer is to use a full path for the script's filename.  Another
  alternative is to fill in the current directory in the appropriate field of
  the scheduler's entry.

  I would prefer setting the current directory, as that allows the
  script to find any data files it needs, but either works.

  I find it useful to only add batch files to the scheduler.  Those batch
  files can do any setup and cleanup necessary.  In this case, the batch file
  might simply set the current directory to the location of the script.

  And that is an excellent idea. Definitely recommended.

  ChrisA

 If it hasn't been mentioned already:

 import time

 while True:
      t1 = time.time()

      #your code here

      t2 = time.time()
      time.sleep( 86400 - (t2 - t1) )

 This doesn't take into account leap seconds, but it doesn't depend on a
 task scheduler.  It is also independent of the time your code takes to
 execute.

 This is simpler, but it might drift slightly over time.

 --
 Bill

Well, I specified the full path name but it still doesn't seem to
work. A DOS prompt flashes for about a second that says taskeng.exe
in the title bar, but the script itself still isn't being run.

I don't know about batch files but I'll read up on them and see if
that will be a better solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-26 Thread John Salerno
On Jul 9, 9:01 pm, John Salerno johnj...@gmail.com wrote:
 Thanks everyone! I probably should have said something like Python,
 if possible and efficient, otherwise any other method ! :)

 I'll look into the Task Scheduler. Thanks again!

Hmm, okay I'm finally trying Task Scheduler, but how do I set it to
run a Python script? It seems to not work, I suppose because it's
running the script but doesn't know how to find Python to run it
properly.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-26 Thread Ethan Furman

John Salerno wrote:

On Jul 9, 9:01 pm, John Salerno johnj...@gmail.com wrote:

Thanks everyone! I probably should have said something like Python,
if possible and efficient, otherwise any other method ! :)

I'll look into the Task Scheduler. Thanks again!


Hmm, okay I'm finally trying Task Scheduler, but how do I set it to
run a Python script? It seems to not work, I suppose because it's
running the script but doesn't know how to find Python to run it
properly.


You need to have Python be the command, then add the script as the 
parameter (you may need to right-click and go to properties... or 
something like that ;) .


~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-26 Thread Andrew Berg
On 2011.07.26 08:05 PM, John Salerno wrote:
 Hmm, okay I'm finally trying Task Scheduler, but how do I set it to
 run a Python script? It seems to not work, I suppose because it's
 running the script but doesn't know how to find Python to run it
 properly.
Tell it to run the Python interpreter and pass the script as an argument.

-- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-26 Thread John Salerno
On Jul 26, 9:22 pm, Andrew Berg bahamutzero8...@gmail.com wrote:
 On 2011.07.26 08:05 PM,JohnSalernowrote: Hmm, okay I'm finally trying Task 
 Scheduler, but how do I set it to
  run a Python script? It seems to not work, I suppose because it's
  running the script but doesn't know how to find Python to run it
  properly.

 Tell it to run the Python interpreter and pass the script as an argument.

 --
 CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
 PGP/GPG Public Key ID: 0xF88E034060A78FCB

Thank you. I changed it as suggested so that now it runs C:
\Python32\python.exe extract_songs.py but it still isn't working. A
DOS prompt flashes real quick as it runs, but when I check the output
file that is supposed to be written to, nothing new has been added.
I'm not sure what the problem is now. I know the script itself works
because I just ran it manually and the output was fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-14 Thread monkeys paw

On 7/9/2011 10:01 PM, John Salerno wrote:

Thanks everyone! I probably should have said something like Python,
if possible and efficient, otherwise any other method ! :)

I'll look into the Task Scheduler. Thanks again!


You could use the below code. time.sleep(# seconds in a day)
where i == 30 would run once a day for a month

import time
i=0
while (1):
print 'hello'
time.sleep(2)   # Change this to number of seconds in a day
if (i == 3):# make this 30 for a month
break
i = i + 1


--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-14 Thread Ian Kelly
On Thu, Jul 14, 2011 at 11:00 AM, monkeys paw mon...@joemoney.net wrote:
 You could use the below code. time.sleep(# seconds in a day)
 where i == 30 would run once a day for a month

 import time
 i=0
 while (1):
        print 'hello'
        time.sleep(2)   # Change this to number of seconds in a day
        if (i == 3):    # make this 30 for a month
                break
        i = i + 1

If the system ever gets rebooted during that month, then you would
need to remember to manually restart the script.  Or if the effective
part of the script raises an exception, it could crash the whole
script without some defensive coding.  That's why it's better just to
use the system scheduler service.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-10 Thread Rafael Durán Castañeda

On 10/07/11 04:01, John Salerno wrote:

Thanks everyone! I probably should have said something like Python,
if possible and efficient, otherwise any other method ! :)

I'll look into the Task Scheduler. Thanks again!
You may use Celery 
http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-10 Thread Paul Rudin
John Salerno johnj...@gmail.com writes:

 I have a script that does some stuff that I want to run every day for
 maybe a week, or a month. So far I've been good about running it every
 night, but is there some way (using Python, of course) that I can make
 it automatically run at a set time each night?

Well - you can make a long lived python process that puts itself to
sleep for 24 hours and then wakes up and does stuff, but the normal
approach to this kind of thing is to use cron. On windows there's also
some kind of scheduler.

-- 
http://mail.python.org/mailman/listinfo/python-list


How can I make a program automatically run once per day?

2011-07-09 Thread John Salerno
I have a script that does some stuff that I want to run every day for
maybe a week, or a month. So far I've been good about running it every
night, but is there some way (using Python, of course) that I can make
it automatically run at a set time each night?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Andrew Berg
On 2011.07.09 07:26 PM, John Salerno wrote:
 I have a script that does some stuff that I want to run every day for
 maybe a week, or a month. So far I've been good about running it every
 night, but is there some way (using Python, of course) that I can make
 it automatically run at a set time each night?
I would use the OS to worry about scheduling (cron/Windows Task
Scheduler/whatever), but in Python, you could probably use a while True
loop, time.sleep() (to specify how often to check the time) and a
datetime.time or datetime.now object (e.g. datetime.now().hour).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Ben Finney
John Salerno johnj...@gmail.com writes:

 is there some way (using Python, of course) that I can make it
 automatically run at a set time each night?

You need to use whatever facilities your operating system has for
scheduled events. That's unrelated to the language you use for
implementing the program.

On a Unix-like system (e.g. GNU+Linux), you could create a ‘cron’ job
entry.

-- 
 \  “The most common way people give up their power is by thinking |
  `\   they don't have any.” —Alice Walker |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Alexander Kapps

On 10.07.2011 02:26, John Salerno wrote:

I have a script that does some stuff that I want to run every day for
maybe a week, or a month. So far I've been good about running it every
night, but is there some way (using Python, of course) that I can make
it automatically run at a set time each night?


Use your operating system's facilities to run timed jobs.

Unix/Linux: Cron jobs
Windows: Scheduled Tasks
Mac: don't know, but probably Cron too
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Cameron Simpson
On 10Jul2011 03:00, Alexander Kapps alex.ka...@web.de wrote:
| On 10.07.2011 02:26, John Salerno wrote:
| I have a script that does some stuff that I want to run every day for
| maybe a week, or a month. So far I've been good about running it every
| night, but is there some way (using Python, of course) that I can make
| it automatically run at a set time each night?
| 
| Use your operating system's facilities to run timed jobs.
| 
| Unix/Linux: Cron jobs
| Windows: Scheduled Tasks
| Mac: don't know, but probably Cron too

Yep. Macs are UNIX, BSD derived.
-- 
Cameron Simpson c...@zip.com.au DoD#743
http://www.cskk.ezoshosting.com/cs/

USENET: Post to exotic, distant machines.  Meet exciting, unusual people.
And flame them. - Dan Sorenson, z1...@exnet.iastate.edu, DoD #1066
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread John Salerno
Thanks everyone! I probably should have said something like Python,
if possible and efficient, otherwise any other method ! :)

I'll look into the Task Scheduler. Thanks again!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Benjamin Kaplan
On Sat, Jul 9, 2011 at 6:58 PM, Cameron Simpson c...@zip.com.au wrote:

 On 10Jul2011 03:00, Alexander Kapps alex.ka...@web.de wrote:
 | On 10.07.2011 02:26, John Salerno wrote:
 | I have a script that does some stuff that I want to run every day for
 | maybe a week, or a month. So far I've been good about running it every
 | night, but is there some way (using Python, of course) that I can make
 | it automatically run at a set time each night?
 |
 | Use your operating system's facilities to run timed jobs.
 |
 | Unix/Linux: Cron jobs
 | Windows: Scheduled Tasks
 | Mac: don't know, but probably Cron too

 Yep. Macs are UNIX, BSD derived.


Macs have Cron, but Apple's trying to switch away from it. They wrote their
own framework to replace the various process-launching programs called
launchd. It uses a pretty simple XML config file to launch programs either
at startup (replacing init) or on an schedule (replacing cron).
-- 
http://mail.python.org/mailman/listinfo/python-list