Python> datetime> runtime arguments> start processing immediately

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.

For import

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

Execution example with wait

$ python util_arg_no_wait_170825.py 
waiting
started

Execution example without wait

$ python util_arg_no_wait_170825.py -n
started

Example of use

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

Python> datetime> runtime arguments> start processing immediately
Receive runtime arguments in Python 2.7
Start python
2017-08-25 Python2> datetime> Wait until start hour, minute, second
python image processing
Python> Run with run-time arguments> Use import argparse
Start using Python
Python quick start
Python file processing
Summary of date processing in Python (datetime and dateutil)
Python distributed processing Spartan
About function arguments (python)
Python SDP runtime comparison
File processing in Python
Python: Natural language processing
Communication processing by Python
Multithreaded processing in python
First Python image processing
Text processing in Python
Queue processing in Python
Python: About function arguments
python unix-time <-> datetime conversion
Image processing with Python
Summary of Python arguments
Python string processing illustration
Various processing of Python