Operating environment
Raspberry Pi 2 Model B (Below RPi)
Raspbian Jessie
Python 2.7.9
Implemented wait processing in Python> datetime> Wait until start time, minute, second.
On the other hand, under certain conditions, you may want to start right away.
Implemented the process to check the run-time arguments.
util_arg_no_wait_170825.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
# PEP8
def hasNoWaitArgument():
parser = argparse.ArgumentParser(description="wait mode")
parser.add_argument(
'-n',
'--noWaitStart',
dest='noWaitStart',
action='store_true',
help='no wait start')
cmd_args = parser.parse_args()
return cmd_args.noWaitStart
if __name__ == '__main__':
if not hasNoWaitArgument():
print('waiting')
# do some wait
print('started')
help
$ python util_arg_no_wait_170825.py -h
usage: util_arg_no_wait_170825.py [-h] [-n]
wait mode
optional arguments:
-h, --help show this help message and exit
-n, --noWaitStart no wait start
$ python util_arg_no_wait_170825.py
waiting
started
$ python util_arg_no_wait_170825.py -n
started
http://qiita.com/7of9/items/0ec6c6b830409dfc0441 If you also use util_wait_170825.py (v0.2).
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
import serial
import datetime
import util_wait_170825 as wai
import util_arg_no_wait_170825 as arg_nw
#=== { Configuration
#start time
ST_HH, ST_MM, ST_SS = 16, 4, 0
#=== }
if not arg_nw.hasNoWaitArgument():
print('waiting')
wai.wait_until(ST_HH, ST_MM, ST_SS)
#Processing something...
Recommended Posts