Re: [Dorset] Can anyone help with using apscheduler in Python?

2016-08-21 Thread Terry Coles
On Sunday, 21 August 2016 16:23:13 BST Ralph Corderoy wrote:
> Going back to your first mail, there's three ways of running it.
> 
> > #!/usr/bin/env python
> 
> ...
> 
> > #!/usr/bin/env python2.7
> 
> ...
> 
> > Python 2.7.12 (default, Jul  1 2016, 15:12:24)
> 
> For the first, env(1) will be using PATH at the time it's run, e.g. by
> cron(8), to find `python', and that might be a 2 or 3 depending on the
> system.  If you know you demand one or the other, e.g. because your code
> is incompatible with 3, then it's better to state it, like in the second
> `#!'.

I see what you mean now.  I would normally define the version, such as in the 
second 
example.  It's just that for these quick and dirty code fragments, I grabbed 
examples off 
the internet and simply ran them to see what would happen; forgetting the 
shebang.

> What was the third?  Is that the output when you run a script under the
> debugger?  (I don't use them much myself.)

Almost; it's the output in the Python Shell.
 
> > The problem was that I'd forgotten to import os ;-)
> 
> Thought it might be.  :-)

> python lacks a `check syntax, but don't run' option.  You can detect
> simple syntax errors before waiting for the next hour to tick around
> with

IDLE has a syntax checker, but IDLE 2 is much more forgiving than Idle 3.  
I tried syntax checking the code in Idle 3, but there is no apscheduler module 
for Python 3, 
so all I got was the 'no module' error.

> python -c 'f = "foo.py"; compile(open(f).read(), f, "exec")'
> 
> And for something to check the semantics, there's
> 
> $ pylint -E foo.py
> No config file found, using default configuration
> * Module foo
> E:  1, 0: Undefined variable 'os' (undefined-variable)
> $
> 
> This kind of thing can be part of your `check' target in your
> ./makefile.  :-)

I will be compiling the finished item so that I can run it efficiently in 
piCore on the Pi Zero, 
but I never thought of compiling it to check the error.

Thanks for your help.  I have another question, but I'll start a new thread ;)

-- 



Terry Coles
-- 
Next meeting:  Bournemouth, Tuesday, 2016-09-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Can anyone help with using apscheduler in Python?

2016-08-21 Thread Ralph Corderoy
Hi Terry,

> Well actually it was in the first line of the shell output at runtime:
>
> Python 2.7.12 (default, Jul  1 2016, 15:12:24) 

Going back to your first mail, there's three ways of running it.

> #!/usr/bin/env python
...
> #!/usr/bin/env python2.7
...
> Python 2.7.12 (default, Jul  1 2016, 15:12:24) 

For the first, env(1) will be using PATH at the time it's run, e.g. by
cron(8), to find `python', and that might be a 2 or 3 depending on the
system.  If you know you demand one or the other, e.g. because your code
is incompatible with 3, then it's better to state it, like in the second
`#!'.

What was the third?  Is that the output when you run a script under the
debugger?  (I don't use them much myself.)

> The problem was that I'd forgotten to import os ;-)

Thought it might be.  :-)

python lacks a `check syntax, but don't run' option.  You can detect
simple syntax errors before waiting for the next hour to tick around
with

python -c 'f = "foo.py"; compile(open(f).read(), f, "exec")'

And for something to check the semantics, there's

$ pylint -E foo.py 
No config file found, using default configuration
* Module foo
E:  1, 0: Undefined variable 'os' (undefined-variable)
$

This kind of thing can be part of your `check' target in your
./makefile.  :-)

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2016-09-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Can anyone help with using apscheduler in Python?

2016-08-21 Thread Terry Coles
On Sunday, 21 August 2016 15:53:47 BST Terry Coles wrote:
> > Add `import logging' to your other imports, and then immediately after
> > try `logging.basicConfig()'.
> 
> I've done that and am currently waiting for the next schedule job to occur
> (1600).  Where should I expect the logger to write its output?

Answering myself; it wrote to the shell :-)

The problem was that I'd forgotten to import os ;-)

-- 



Terry Coles

-- 
Next meeting:  Bournemouth, Tuesday, 2016-09-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

Re: [Dorset] Can anyone help with using apscheduler in Python?

2016-08-21 Thread Ralph Corderoy
Hi Terry,

> No handlers could be found for logger "apscheduler.scheduler"

It's handy for Python questions to state whether it's 2 or 3.  :-)
Running Python in the same method as your script with its --version
option will say.

Add `import logging' to your other imports, and then immediately after
try `logging.basicConfig()'.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2016-09-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

[Dorset] Can anyone help with using apscheduler in Python?

2016-08-21 Thread Terry Coles
Hi,

Most of you are aware by now that Clive and I have a project to bring the 
bells back to the Wimborne Model Town Minster.  I've been experimenting with 
using apscheduler and mpg321 in Python to realise this.  It's pretty crude at 
the moment, but if I run two separate programs (the bells and the schedule) 
both parts work.

Taking mpg321 first; this code works perfectly:

#!/usr/bin/env python
from time import sleep
import os, random

try:
while True:
os.system('mpg321 -g 100 -q ./mp3/amersham.mp3')
sleep(1);

os.system('mpg321 -g 100 -q ./mp3/nottingham_smv.mp3')
sleep(1);

os.system('mpg321 -g 20 -q ./mp3/peterboro.mp3')
sleep(1);

finally:
sleep(1)

Also, here is a fragment of my (separate) scheduling program, without the 
bells:

#!/usr/bin/env python2.7
import datetime
import time
from apscheduler.scheduler import Scheduler

# Start the scheduler
sched = Scheduler()
sched.daemonic = False
sched.start()

def one_oclock():
print("One O'clock")
print(datetime.datetime.now())
time.sleep(1)

# Schedule functions to be run 
sched.add_cron_job(one_oclock,  hour='1')

So far so good.  However, when I combine the two and add the system call to 
mpg321 after the sleep into my functions, eg:

def one_oclock():
print("One O'clock")
print(datetime.datetime.now())
time.sleep(120)
os.system('mpg321 -g 20 -q ./mp3/Wedding_March.mp3')
time.sleep(300)
os.system('mpg321 -g 100 -q ./mp3/amersham.mp3')

I get:

Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> 
 RESTART: /home/terry/Development/Wimborne_Model_Town/Winter_2016-17_Projects/
Code/Minster_Bells/Scheduler_V2.py 
>>> 
2016-08-21 15:15:00.006585
No handlers could be found for logger "apscheduler.scheduler"

The debugger doesn't really help, so how can I find out what I'm doing wrong?

-- 



Terry Coles

-- 
Next meeting:  Bournemouth, Tuesday, 2016-09-06 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR