Python time.hour() Examples

The following are 21 code examples for showing how to use time.hour(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module time , or try the search function .

Example 1
Project: rpi_ai   Author: schollz   File: visual_cortex.py    License: MIT License 6 votes vote down vote up
def saveImage():
	keepDiskSpaceFree(config.diskSpaceToReserve)
	time = datetime.datetime.now()
	filenameFull = config.filepath + config.filenamePrefix + "-%04d%02d%02d%02d%02d%02d" % (time.year, time.month, time.day, time.hour, time.minute, time.second)+ "." + config.fileType
	
	# save onto webserver
	filename = "/var/www/temp.jpg"
	subprocess.call("sudo raspistill -w "+ str(config.saveWidth) +" -h "+ str(config.saveHeight) + " -t 1 -n -vf -e " + config.fileType + " -q 15 -o %s" % filename, shell=True)
	print "Captured image: %s" % filename

	theSpeech = recognizeFace(filename,filenameFull)
	if len(theSpeech)>2:
		print theSpeech
		saySomething(theSpeech,"en")
		config.lookForFaces = 0


# Keep free space above given level 
Example 2
Project: piecewisecrf   Author: Vaan5   File: train.py    License: MIT License 6 votes vote down vote up
def get_expired_time(start_time):
    '''

    Returns expired time in HH:MM:SS format calculated relative to start_time

    Parameters
    ----------
    start_time : int
        Starting point in time


    '''
    curr_time = time.time()
    delta = curr_time - start_time
    hour = int(delta / 3600)
    delta -= hour * 3600
    minute = int(delta / 60)
    delta -= minute * 60
    seconds = delta
    return '%02d' % hour + ':%02d' % minute + ':%02d' % seconds 
Example 3
Project: JuicyRaspberryPie   Author: wensheng   File: minecraft_clock.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def updateTime(mc, clockCentre, lastTime, time):
    #draw hour and minute hand
    if (lastTime.minute != time.minute):
        #clear hour hand
        drawHourHand(mc, clockCentre, lastTime.hour, lastTime.minute, 'air')
        #new hour hand
        drawHourHand(mc, clockCentre, time.hour, time.minute, 'dirt')
        
        #clear hand
        drawMinuteHand(mc, clockCentre, lastTime.minute, 'air')
        #new hand
        drawMinuteHand(mc, clockCentre, time.minute, 'STONE')

    #draw second hand
    if (lastTime.second != time.second):
        #clear hand
        drawSecondHand(mc, clockCentre, lastTime.second, 'AIR')
        #new hand
        drawSecondHand(mc, clockCentre, time.second, 'WOOD_PLANKS') 
Example 4
Project: graphene-django-extras   Author: eamigo86   File: date.py    License: MIT License 5 votes vote down vote up
def _combine_date_time(d, t):
    if (d is not None) and (t is not None):
        return datetime(d.year, d.month, d.day, t.hour, t.minute, t.second)
    return None 
Example 5
Project: In2ItChicago   Author: In2ItChicago   File: time_utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def get_timestamp(self, date, time=None):
        if time != None:
            date += relativedelta(hour=time.hour, minute=time.minute)
        return self.datetime_to_timestamp(date) 
Example 6
Project: In2ItChicago   Author: In2ItChicago   File: time_utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def min_timestamp_for_day(self, date):
        if isinstance(date, str):
            date = self.parse_date_string(date)
        return self.get_timestamp(date + relativedelta(hour=0, minute=0)) 
Example 7
Project: In2ItChicago   Author: In2ItChicago   File: time_utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def max_timestamp_for_day(self, date):
        if isinstance(date, str):
            date = self.parse_date_string(date)
        return self.get_timestamp(date + relativedelta(hour=23, minute=59)) 
Example 8
Project: In2ItChicago   Author: In2ItChicago   File: time_utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def set_to_midnight(self, parsed_date):
        return parsed_date.replace(hour = 0, minute = 0, second = 0, microsecond = 0) 
Example 9
Project: piecewisecrf   Author: Vaan5   File: train.py    License: MIT License 5 votes vote down vote up
def get_time_string():
    '''

    Returns current time in day_month_HH-MM-SS/ format

    '''
    time = datetime.now()
    name = (str(time.day) + '_' + str(time.month) + '_%02d' % time.hour +
            '-%02d' % time.minute + '-%02d' % time.second + '/')
    return name 
Example 10
Project: piecewisecrf   Author: Vaan5   File: train.py    License: MIT License 5 votes vote down vote up
def get_time():
    '''

    Returns current time in HH:MM:SS format

    '''
    time = datetime.now()
    return '%02d' % time.hour + ':%02d' % time.minute + ':%02d' % time.second 
Example 11
Project: luscan-devel   Author: blackye   File: datetime_safe.py    License: GNU General Public License v2.0 5 votes vote down vote up
def combine(self, date, time):
        return datetime(date.year, date.month, date.day, time.hour, time.minute, time.microsecond, time.tzinfo) 
Example 12
Project: luscan-devel   Author: blackye   File: datetime_safe.py    License: GNU General Public License v2.0 5 votes vote down vote up
def new_datetime(d):
    """
    Generate a safe datetime from a datetime.date or datetime.datetime object.
    """
    kw = [d.year, d.month, d.day]
    if isinstance(d, real_datetime):
        kw.extend([d.hour, d.minute, d.second, d.microsecond, d.tzinfo])
    return datetime(*kw)

# This library does not support strftime's "%s" or "%y" format strings.
# Allowed if there's an even number of "%"s because they are escaped. 
Example 13
Project: JuicyRaspberryPie   Author: wensheng   File: minecraft_clock.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def drawClock(mc, clockCentre, radius, time):
    drawCircle(mc, clockCentre.x, clockCentre.y, clockCentre.z, radius, 'DIAMOND_BLOCK')
    drawHourHand(mc, clockCentre, time.hour, time.minute, 'DIRT')
    drawMinuteHand(mc, clockCentre, time.minute, 'STONE')
    drawSecondHand(mc, clockCentre, time.second, 'WOOD_PLANKS') 
Example 14
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: datetime_safe.py    License: Apache License 2.0 5 votes vote down vote up
def combine(self, date, time):
        return datetime(date.year, date.month, date.day, time.hour, time.minute, time.microsecond, time.tzinfo) 
Example 15
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: datetime_safe.py    License: Apache License 2.0 5 votes vote down vote up
def new_datetime(d):
    """
    Generate a safe datetime from a datetime.date or datetime.datetime object.
    """
    kw = [d.year, d.month, d.day]
    if isinstance(d, real_datetime):
        kw.extend([d.hour, d.minute, d.second, d.microsecond, d.tzinfo])
    return datetime(*kw)

# This library does not support strftime's "%s" or "%y" format strings.
# Allowed if there's an even number of "%"s because they are escaped. 
Example 16
Project: suds   Author: suds-community   File: date.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def _bump_up_time_by_microsecond(time):
    """
    Helper function bumping up the given datetime.time by a microsecond,
    cycling around silently to 00:00:00.0 in case of an overflow.

    @param time: Time object.
    @type time: B{datetime}.I{time}
    @return: Time object.
    @rtype: B{datetime}.I{time}

    """
    dt = datetime.datetime(2000, 1, 1, time.hour, time.minute,
        time.second, time.microsecond)
    dt += datetime.timedelta(microseconds=1)
    return dt.time() 
Example 17
Project: suds   Author: suds-community   File: date.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def _time_from_match(match_object):
    """
    Create a time object from a regular expression match.

    Returns the time object and information whether the resulting time should
    be bumped up by one microsecond due to microsecond rounding.

    Subsecond information is rounded to microseconds due to a restriction in
    the python datetime.datetime/time implementation.

    The regular expression match is expected to be from _RE_DATETIME or
    _RE_TIME.

    @param match_object: The regular expression match.
    @type match_object: B{re}.I{MatchObject}
    @return: Time object + rounding flag.
    @rtype: tuple of B{datetime}.I{time} and bool

    """
    hour = int(match_object.group('hour'))
    minute = int(match_object.group('minute'))
    second = int(match_object.group('second'))
    subsecond = match_object.group('subsecond')

    round_up = False
    microsecond = 0
    if subsecond:
        round_up = len(subsecond) > 6 and int(subsecond[6]) >= 5
        subsecond = subsecond[:6]
        microsecond = int(subsecond + "0" * (6 - len(subsecond)))
    return datetime.time(hour, minute, second, microsecond), round_up 
Example 18
Project: docassemble   Author: jhpyle   File: util.py    License: MIT License 5 votes vote down vote up
def today(timezone=None, format=None):
    """Returns today's date at midnight as a DADateTime object."""
    ensure_definition(timezone, format)
    if timezone is None:
        timezone = get_default_timezone()
    val = pytz.utc.localize(datetime.datetime.utcnow()).astimezone(pytz.timezone(timezone))
    if format is not None:
        return dd(val.replace(hour=0, minute=0, second=0, microsecond=0)).format_date(format)
    else:
        return dd(val.replace(hour=0, minute=0, second=0, microsecond=0)) 
Example 19
Project: docassemble   Author: jhpyle   File: util.py    License: MIT License 5 votes vote down vote up
def replace_time(self, time):
        return self.replace(hour=time.hour, minute=time.minute, second=time.second, microsecond=time.microsecond) 
Example 20
Project: docassemble   Author: jhpyle   File: util.py    License: MIT License 5 votes vote down vote up
def dd(obj):
    if isinstance(obj, DADateTime):
        return obj
    return DADateTime(obj.year, month=obj.month, day=obj.day, hour=obj.hour, minute=obj.minute, second=obj.second, microsecond=obj.microsecond, tzinfo=obj.tzinfo) 
Example 21
Project: docassemble   Author: jhpyle   File: util.py    License: MIT License 5 votes vote down vote up
def dt(obj):
    return datetime.datetime(obj.year, obj.month, obj.day, obj.hour, obj.minute, obj.second, obj.microsecond, obj.tzinfo)