Re: [Dorset] Another question about using apscheduler in Python?

2016-08-21 Thread Ralph Corderoy
Hi Terry,

> I have Learning Python (
> http://shop.oreilly.com/product/0636920028154.do ) in paper and
> ebook versions.

I haven't, but a look on the Internet suggests "Arbitrary Arguments
Examples" in Ch. 18, "Arguments", shows you how apschedule is saving
that `args=(1,)' tuple you're passing it as a named argument and then
calling your function with its values as parameters later on.

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] Another question about using apscheduler in Python?

2016-08-21 Thread Terry Coles
On Sunday, 21 August 2016 18:13:14 BST Peter Merchant wrote:
> What book do you have? I have two free ebooks on it byteofpython,
> http://python.swaroopch.com/ and diveintopython.
> http://www.diveintopython.net/

I paid for mine :-)

I have Learning Python ( http://shop.oreilly.com/product/0636920028154.do[1] ) 
in 
paper and ebook versions.

-- 



Terry Coles


[1] http://shop.oreilly.com/product/0636920028154.do
-- 
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] Another question about using apscheduler in Python?

2016-08-21 Thread Peter Merchant

On 21/08/16 16:50, Terry Coles wrote:

OK.I couldn't see an example in my Python
book, so kind of ran out of ideas.

Does anyone know what will work?

What book do you have? I have two free ebooks on it byteofpython, 
http://python.swaroopch.com/ and diveintopython. 
http://www.diveintopython.net/



Peter



--
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] Another question about using apscheduler in Python?

2016-08-21 Thread Ralph Corderoy
Hi Terry,

> On the piCore forum, the guys were trying to get me to use asyncio,
> instead of apscheduler, but I found a total lack of suitable examples
> and I got the impression that it wasn't really intended for what I
> wanted to do; it just was possible.

asyncio is a new whizzy thing added to Python in recent times, since
I've stopped paying attention to it, to play catch up with other
languages and libraries in a way that's standard for the language rather
than a third party, like Twisted.  It could be it's the solution for
everything at the moment.  :-)

> (I also found the documentation totally incomprehensible to my
> hardware oriented brain.)

Don't think that's your brain, I think that's what trying to shoehorn
asynchronicity in as an backwards-compatible afterthought gets you.

What's the requirement?  To play one pattern of MP3s on the hour, and
another on every quarter?  Have you considered two little shell scripts
with your commands, taken from the os.system()s and using sleep(1), with
two crontab(5) entries,

0 * * * * .../play-hour
15,30,45 * * * * .../play-quarter

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] Another question about using apscheduler in Python?

2016-08-21 Thread Terry Coles
On Sunday, 21 August 2016 17:10:32 BST Ralph Corderoy wrote:
> Try
> 
> sched.add_cron_job(hours, args=('1',))
> 
> And look for `args' and `kwargs' in the documentation for the add*
> functions you're using.  It's a Python convention, but not part of the
> language;  apscheduler will have explicit code to stash away the tuple
> or list you pass as the `args' named parameter and to retrieve it later
> to pass to your function.

Thanks.  I'll have a look at that tomorrow; there's no rush, we've got until 
next April :-)  I've just been trying to find out what's possible.

On the piCore forum, the guys were trying to get me to use asyncio, instead of 
apscheduler, but I found a total lack of suitable examples and I got the 
impression that it wasn't really intended for what I wanted to do; it just was 
possible.  (I also found the documentation totally incomprehensible to my 
hardware oriented brain.)  Anyway, one of the guys there is now looking into 
adding apscheduler as a piCore extension.  If it proves difficult, I might 
still 
have to look into using asyncio, but all these stumbling blocks will still 
help me avoid the same problems later.

BTW, pylint is extremely useful and does a far better job of checking for 
errors than Idle.  Most important of all is that it doesn't stop when it hits 
the first error.

-- 



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] Another question about using apscheduler in Python?

2016-08-21 Thread Ralph Corderoy
Hi Terry,

> sched.add_cron_job(hours(1),  hour='1')
>
> with the function redefined as:
>
> def hours(hour):
> print(hour + "O'clock")

That will call hours() to work out the parameter to pass to
add_cron_job().

Try

sched.add_cron_job(hours, args=('1',))

And look for `args' and `kwargs' in the documentation for the add*
functions you're using.  It's a Python convention, but not part of the
language;  apscheduler will have explicit code to stash away the tuple
or list you pass as the `args' named parameter and to retrieve it later
to pass to your function.

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] Another question about using apscheduler in Python?

2016-08-21 Thread Terry Coles
OK.  So now my code runs, but it isn't very efficient.  Currently I have one of 
these for every hour and every quarter throughout the day:

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')

The reason is that I couldn't work out how to pass arguments in the call in 
the list of scheduled functions to be run:

sched.add_cron_job(one_oclock,  hour='1')

I think I'll still need an entry in the schedule for each event, but I feel I 
ought to be able to create a single function for hours and another for 
quarters and get the calling cron_job to pass the hour or minute into it.  I 
tried:

sched.add_cron_job(hours(1),  hour='1')

with the function redefined as:

def hours(hour):
print(hour + "O'clock")


Unfortunately, when I tried it I got run-time errors because of argument 
mismatches (I tried (1) and ('One').  I couldn't see an example in my Python 
book, so kind of ran out of ideas.

Does anyone know what will work?

-- 



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 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

Re: [Dorset] No Ethernet and other problems

2016-08-21 Thread Ralph Corderoy
Hi Tim,

> I ran "inxi -n" and according to that the Ethernet adaptor is an Intel
> I217-LM which use the e1000-e driver. I ran lsmod which is saying that
> the driver is loaded but unused. Booting the PC into windows show that
> the Ethernet does work without a problem so it seems to be undamaged
> thus a Linux issue.

Have you had a peruse of dmesg's output from booting?  These two threads
may help.  Either the driver is too old and one is available from Intel,
or disable lots of NIC power-management stuff from Windows.


https://ubuntuforums.org/showthread.php?t=2280968=2=13299512#post13299512
https://bbs.archlinux.org/viewtopic.php?pid=1491432#p1491432

> Is there anything that I can use in Linux to monitor the sensors or
> just ignore as it is just the sensors getting it wrong?

Is Linux hampered by the false, or out of date, sensor reading?  Or are
you just trying to use Linux to pacify Windows because you still intend
to run both?

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] No Ethernet and other problems

2016-08-21 Thread Tim
I have a bit of an odd ball one here. I have acquired a Laptop with a 
smashed screen, I have removed the LCD screen and hooked up the laptop 
to an external monitor. I have booted from the latest SolydX 64bit DVD 
which comes up using the ext. display as the main display. The wireless 
works but I don't seem to be able to get the Ethernet up and running. I 
have tried setting the Ethernet to static IP but that made no difference.


I ran "inxi -n" and according to that the Ethernet adaptor is an Intel 
I217-LM which use the e1000-e driver. I ran lsmod which is saying that 
the driver is loaded but unused. Booting the PC into windows show that 
the Ethernet does work without a problem so it seems to be undamaged 
thus a Linux issue.


Second problem, in windows the laptop keeps complaining that the shock 
sensor utility has detected a shock and retracted the heads on the hard 
disk (this happens even when the laptop is just sat on the table with 
nobody touching it). I am guessing the issue is that the sensor(s) which 
were mounted in the lid of the laptop are sending false signals to the 
utility (all cables are carefully wound up and stuck to the inside the 
lid). I only cut one cable and that was the display as it was hard wired 
to the screen (guess it is plugged in on the mother board). Is there 
anything that I can use in Linux to monitor the sensors or just ignore 
as it is just the sensors getting it wrong?


The idea is to use the laptop as a desktop PC with a wireless keyboard 
and mouse and external monitor and keep the laptop under the desk.


Any thoughts?


Tim


--
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