Python time.minute() Examples

The following are code examples for showing how to use time.minute(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: readysetstem-api   Author: readysetstem   File: stuffaboutcode_clock.py    Apache License 2.0 6 votes vote down vote up
def drawClock(mc, clockCentre, radius, time):
    
    blockType = block.DIAMOND_BLOCK
    #draw the circle
    drawCircle(mc, clockCentre.x, clockCentre.y, clockCentre.z, radius, blockType)

    #draw hour hand
    drawHourHand(mc, clockCentre, time.hour, time.minute, block.DIRT)
    
    #draw minute hand
    drawMinuteHand(mc, clockCentre, time.minute, block.STONE)

    #draw second hand
    drawSecondHand(mc, clockCentre, time.second, block.WOOD_PLANKS)

#function to update the time on the clock 
Example 2
Project: readysetstem-api   Author: readysetstem   File: stuffaboutcode_clock.py    Apache License 2.0 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, block.AIR)
        #new hour hand
        drawHourHand(mc, clockCentre, time.hour, time.minute, block.DIRT)
        
        #clear hand
        drawMinuteHand(mc, clockCentre, lastTime.minute, block.AIR)
        #new hand
        drawMinuteHand(mc, clockCentre, time.minute, block.STONE)

    #draw second hand
    if (lastTime.second != time.second):
        #clear hand
        drawSecondHand(mc, clockCentre, lastTime.second, block.AIR)
        #new hand
        drawSecondHand(mc, clockCentre, time.second, block.WOOD_PLANKS) 
Example 3
Project: Top-Radio-to-spotify   Author: dpasut   File: playlist.py    MIT License 6 votes vote down vote up
def get_edge_data():
    soup = BeautifulSoup(requests.get('https://edge.ca/music/').content,
                         'html.parser')
    date = to_epoch(dateutil.parser.parse(
        soup.find(id='playlist-select').findAll('option')[2].text.strip()))
    songs = json.loads(requests.get(BASE_LINK_EDGE,
                                    headers={'User-Agent': USER_AGENT})
                       .content[:-1].replace('plCallback(', ''))['songs']
    res = []
    prev = None
    offset = 0
    for s in tqdm(songs):
        try:
            if prev == 'PM' and s['date'][-2:] == 'AM':
                offset += 1
            prev = s['date'][-2:]
            time = datetime.strptime(s['date'], "%H:%M%p")
            time = (60 * 60 * time.hour) + (60 * time.minute) + time.second
            time = date + time - (offset * 60 * 60 * 24)
        except:
            continue
        res.append({'artist_name': s['artist'],
                    'song_name': s['song'],
                    'last_played': int(time)})
    return {'data': {'songs': res}}, int(date) 
Example 4
Project: piecewisecrf   Author: Vaan5   File: train.py    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 5
Project: jabbapylib3   Author: jabbalaci   File: dateandtime.py    MIT License 6 votes vote down vote up
def get_timestamp_from_year_to_second(separator=False, date=None):
    """A compact timestamp.

    Example: 20110523_234401 . date can be a datetime object.
    If date is not specified, the current date and time (now) will be used."""
    if date:
        now = date
    else:
        now = datetime.now()
    date = datetime.date(now)
    time = datetime.time(now)
    #return "%d-%02d-%02d @ %02dh%02d%02d" % (date.year, date.month, date.day, time.hour, time.minute, time.second)
    template = "{year}{month:02}{day:02}_{hour:02}{minute:02}{second:02}"
    if separator:
        template = "{year}_{month:02}_{day:02}_{hour:02}{minute:02}{second:02}"
    return template.format(year=date.year, month=date.month, day=date.day, hour=time.hour, minute=time.minute, second=time.second) 
Example 6
Project: JuicyRaspberryPie   Author: wensheng   File: minecraft_clock.py    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 7
Project: SamPy   Author: sniemi   File: footprintfinder.py    BSD 2-Clause "Simplified" License 6 votes vote down vote up
def getdatetime(time=None):

#------------------------------------------------------------------------------------------------
    '''
       returns a SYBSE accepted datetime string. If no datetime object is given, it returns
       the (local) time.
    '''
    import datetime

    if time == None:
        time = datetime.datetime.utcnow()

    return "%04d-%02d-%02d %02d:%02d:%02d" % (time.year, time.month, time.day, time.hour, time.minute, time.second)


#------------------------------------------------------------------------------------------------ 
Example 8
Project: Thermostat_v5   Author: jpnos26   File: thermostat.py    MIT License 6 votes vote down vote up
def update_clock(self, *args):
        if self.black_screen == 1:
            if pirEnabled:
                if GPIO.input(pirPin):
                    log(LOG_LEVEL_INFO, CHILD_DEVICE_PIR, MSG_SUBTYPE_TRIPPED, "1")
                    GPIO.output(lightPin, GPIO.HIGH)
                    log(LOG_LEVEL_DEBUG, CHILD_DEVICE_SCREEN, MSG_SUBTYPE_TEXT, "Full")
                    minScreen.return_screen(self)
        else:
            self.canvas.clear()
            with self.canvas:
                time = datetime.datetime.now()
                Color(0.1, 0.8, 0.2,0.2)
                Line(points=[self.center_x, self.center_y, self.center_x+0.8*self.r*sin(pi/30*time.second), self.center_y+0.8*self.r*cos(pi/30*time.second)], width=1, cap="round")
                Color(0.3, 0.8, 0.3,0.2)
                Line(points=[self.center_x, self.center_y, self.center_x+0.7*self.r*sin(pi/30*time.minute), self.center_y+0.7*self.r*cos(pi/30*time.minute)], width=2, cap="round")
                Color(0.4, 0.7, 0.4,0.2)
                th = time.hour*60 + time.minute
                Line(points=[self.center_x, self.center_y, self.center_x+0.5*self.r*sin(pi/360*th), self.center_y+0.5*self.r*cos(pi/360*th)], width=3, cap="round")

###### dht page dynamically loaded ################################################################ 
Example 9
Project: Thermostat_v5   Author: jpnos26   File: thermostat.py    MIT License 6 votes vote down vote up
def getTestSchedule():
    days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
    testSched = {}
    for i in range(len(days)):
        tempList = []
        for minute in range(60 * 24):
            hrs, mins = divmod(minute, 60)
            tempList.append([
                str(hrs).rjust(2, '0') + ":" + str(mins).rjust(2, '0'),
                float(i + 1) / 10.0 + ((19.0 if tempScale == "metric" else 68.0) if minute % 2 == 1 else (
                22.0 if tempScale == "metric" else 72.0))
            ])

        testSched[days[i]] = tempList

    return testSched 
Example 10
Project: TESTGIT   Author: B-ROY   File: datetime_safe.py    Apache License 2.0 5 votes vote down vote up
def combine(cls, date, time):
        return cls(date.year, date.month, date.day,
                   time.hour, time.minute, time.second,
                   time.microsecond, time.tzinfo) 
Example 11
Project: TESTGIT   Author: B-ROY   File: datetime_safe.py    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 12
Project: raspi_integrations   Author: josiasMO   File: Gprs.py    MIT License 5 votes vote down vote up
def get_time(self):
        """
        Get time from gprs tracker, and clean the serial buffer
        return a list with the date and time
            [y_high, y_low, month, day, hour, minute, second ]
        """
        try:
            conn = serial.Serial("/dev/ttyS0", 115200, timeout=1)
            conn.flushInput()
            #get gprs time
            conn.write('AT+CCLK?'.encode('utf-8')+b'\r\n')
            conn.flush()
        except serial.SerialException:
            return ['0']*7

        received = conn.read(56).decode('utf-8').split('+CCLK: ')
        for line in received:
            if(line.startswith('"')):
                time = line[:19]
            else:
                time = None

        #clean buffer and close pyserial
        conn.flushInput()
        conn.flushOutput()
        conn.close()
        #check if the gprs tracker answered with the time
        try:
            if (len(time) > 1):
                #convert string to datetime
                time = datetime.strptime(time, '"%y/%m/%d,%H:%M:%S"')
                date_list = [time.year - 2000, \
                    time.month, time.day, time.hour, time.minute, time.second]
                return [str(a) for a in date_list]
            else: return ['0']*7
        except (IndexError,UnboundLocalError,TypeError): return ['0']*7 
Example 13
Project: PassiveOSFingerprint   Author: CSIRT-MU   File: run.py    MIT License 5 votes vote down vote up
def round_time(time):
    """
    Get time of last flowmon export.
    :param time: current time.
    :return: rounded time.
    """
    t_min = time.minute % 5
    t_sec = time.second
    t_mic = time.microsecond
    time = time - timedelta(minutes=t_min, seconds=t_sec, microseconds=t_mic)
    return time 
Example 14
Project: GeoMop   Author: GeoMop   File: exec_with_limit.py    GNU General Public License v3.0 5 votes vote down vote up
def parse_float(value):
    """
    Simple method for converting duration value
    Supported format are either number value or HH:MM:SS format

    :type value: str
    :rtype: float
    """
    value = str(value)
    try:
        return float(value)
    except ValueError:
        time = datetime.strptime(value, "%H:%M:%S")
        delta = timedelta(hours=time.hour, minutes=time.minute, seconds=time.second)
        return delta.total_seconds() 
Example 15
Project: Build-CNN-or-LSTM-or-CNNLSTM-with-speech-features   Author: a-n-rose   File: extract_features.py    MIT License 5 votes vote down vote up
def get_date():
    '''
    This creates a string of the day, hour, minute and second
    I use this to make folder names unique
    
    For the files themselves, I generate genuinely unique names (i.e. name001.csv, name002.csv, etc.)
    '''
    time = datetime.datetime.now()
    time_str = "{}y{}m{}d{}h{}m{}s".format(time.year,time.month,time.day,time.hour,time.minute,time.second)
    return(time_str) 
Example 16
Project: forum-xblock   Author: DANCEcollaborative   File: datetime_safe.py    MIT License 5 votes vote down vote up
def combine(cls, date, time):
        return cls(date.year, date.month, date.day,
                   time.hour, time.minute, time.second,
                   time.microsecond, time.tzinfo) 
Example 17
Project: forum-xblock   Author: DANCEcollaborative   File: datetime_safe.py    MIT License 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 18
Project: genetic-algorithm-with-Spark-for-test-generation   Author: paduraru2009   File: functors.py    MIT License 5 votes vote down vote up
def saveCrashData(self, tracerProcess, inputString):
        from utils import logsFullPath
        error_type = {
            signal.SIGHUP: 'hup',
            signal.SIGINT: 'int',
            signal.SIGQUIT: 'quit',
            signal.SIGILL: 'ill',
            signal.SIGTRAP: 'trap',
            signal.SIGABRT: 'abrt',
            signal.SIGBUS: 'bus',
            signal.SIGFPE: 'fpe',
            signal.SIGUSR1: 'usr1',
            signal.SIGSEGV: 'segv',
            signal.SIGUSR2: 'usr2',
            signal.SIGPIPE: 'pipe',
            signal.SIGALRM: 'alrm',
            signal.SIGTERM: 'term'
        }

        signalCode = -tracerProcess.returncode
        
        if logsFullPath == "":
            logsFullPath = '/home/boc/genetic-algorithm-with-Spark-for-test-generation/logs' 
        folder = logsFullPath + '/crash/' + error_type[signalCode]

        # Create folder if it doesn't exist
        os.makedirs(folder, exist_ok=True)

        # Create new file and save the input that caused the crash
        from uuid import uuid4
        from datetime import datetime

        time = datetime.now()
        time_str = "%d-%d-%d->%d-%d-%d" % (time.day, time.month, time.year,
                                           time.hour, time.minute, time.second)
        file_name = error_type[signalCode] + '-' + time_str + '-' + str(uuid4())[:8]

        with open(folder + '/' + file_name + '.bin', 'wb') as f:
            f.write(bytearray(inputString)) 
Example 19
Project: graphene-django-extras   Author: eamigo86   File: date.py    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 20
Project: partytime   Author: sunlightlabs   File: feeds.py    GNU General Public License v3.0 5 votes vote down vote up
def _date_time_to_datetime(date, time=None):
    if not time:
        time = datetime.time()
    return datetime.datetime(date.year, date.month, date.day, time.hour, time.minute, time.second) 
Example 21
Project: piecewisecrf   Author: Vaan5   File: train.py    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 22
Project: piecewisecrf   Author: Vaan5   File: train.py    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 23
Project: luscan-devel   Author: blackye   File: datetime_safe.py    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 24
Project: luscan-devel   Author: blackye   File: datetime_safe.py    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 25
Project: jabbapylib3   Author: jabbalaci   File: dateandtime.py    MIT License 5 votes vote down vote up
def get_time():
    """
    Current time (HHMM).

    The return value is a string.
    """
    now = datetime.now()
    time = datetime.time(now)
    return "{hour:02}{minute:02}".format(hour=time.hour, minute=time.minute) 
Example 26
Project: ClipboardApp   Author: ClipboardProject   File: time_utils.py    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 27
Project: ClipboardApp   Author: ClipboardProject   File: time_utils.py    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 28
Project: ClipboardApp   Author: ClipboardProject   File: time_utils.py    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 29
Project: ClipboardApp   Author: ClipboardProject   File: time_utils.py    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 30
Project: JuicyRaspberryPie   Author: wensheng   File: minecraft_clock.py    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 31
Project: global-ssh-server   Author: nthiep   File: datetime_safe.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def combine(cls, date, time):
        return cls(date.year, date.month, date.day,
                   time.hour, time.minute, time.second,
                   time.microsecond, time.tzinfo) 
Example 32
Project: global-ssh-server   Author: nthiep   File: datetime_safe.py    GNU Affero General Public License v3.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 33
Project: DDoS_Information_Sharing   Author: c2theg   File: date.py    MIT License 5 votes vote down vote up
def __init__(self, offset):
        """
        @param offset: The fixed offset of the timezone.
        @type offset: I{int} or B{datetime}.I{timedelta}

        """
        if type(offset) == int:
            offset = datetime.timedelta(hours=offset)
        elif type(offset) != datetime.timedelta:
            raise TypeError("timezone offset must be an int or "
                "datetime.timedelta")
        if offset.microseconds or (offset.seconds % 60 != 0):
            raise ValueError("timezone offset must have minute precision")
        self.__offset = offset 
Example 34
Project: DDoS_Information_Sharing   Author: c2theg   File: date.py    MIT License 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 value: 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 35
Project: DDoS_Information_Sharing   Author: c2theg   File: date.py    MIT License 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 value: 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 36
Project: MONITT   Author: meeeejin   File: datetime_safe.py    MIT License 5 votes vote down vote up
def combine(cls, date, time):
        return cls(date.year, date.month, date.day,
                   time.hour, time.minute, time.second,
                   time.microsecond, time.tzinfo) 
Example 37
Project: MONITT   Author: meeeejin   File: datetime_safe.py    MIT License 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 38
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: datetime_safe.py    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 39
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: datetime_safe.py    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 40
Project: alarm   Author: G8bao7   File: datetime_safe.py    Apache License 2.0 5 votes vote down vote up
def combine(cls, date, time):
        return cls(date.year, date.month, date.day,
                   time.hour, time.minute, time.second,
                   time.microsecond, time.tzinfo) 
Example 41
Project: alarm   Author: G8bao7   File: datetime_safe.py    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 42
Project: Namsor-API-Wrapper-Python   Author: JosephPallipadan   File: datetime_safe.py    MIT License 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 43
Project: Namsor-API-Wrapper-Python   Author: JosephPallipadan   File: datetime_safe.py    MIT License 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 44
Project: Thermostat_v5   Author: jpnos26   File: thermostat.py    MIT License 4 votes vote down vote up
def crono(self,*args):
        with thermostatLock:
            self.main_time = time.strftime("%H : %M").lower()
            self.main_date = time.strftime("[size=18]%d - %B - %Y[/size]").lower()
            self.main_explain = ""
            self.main_state == 0
            data_main = con.execute("select * from data where Id == 1")
            for row in data_main.fetchall():
                #print row
                if (row[5] != None):
                    self.main_umidita = str(int(row[5]))+" % - "+str(int(row[6]))+" mBar"
                else:
                    self.main_umidita =""
                if row[4] > row[14]:
                    self.main_tendenza = "web/images/tendenzasu1.png"
                #elif (row[14] >= 0.31):
                #    self.main_tendenza = "web/images/tendenzasu2.png"
                elif (row[4] < row[14]):
                    self.main_tendenza = "web/images/tendenzagiu1.png"
                #elif (row[14] <= -0.31):
                #    self.main_tendenza = "web/images/tendenzagiu2.png"
                else:
                    self.main_tendenza = "web/images/tendenzauguale.png"
                if row[4] == 100:
                    self.main_temp.text = "-.-"
                else:
                    self.main_temp.text = str(round(row[4],1))+"°"
                self.slider_color = row[1]
                if (row[8] == 1):
                    self.main_setTemp = str(round(row[3],1))
                    self.main_state = 1
                    try:
                        self.main_explain = "[color=#fca62c]- Auto -[/color]"
                        self.main_next = "[size=12] {:0>2d}".format(schedule.next_run().hour)+":"+"{:0>2d}".format(schedule.next_run().minute)+" --> "+str(min(schedule.jobs))[str(min(schedule.jobs)).find("(")+1:str(min(schedule.jobs)).find(")")]+"[/size]"
                    except:
                        self.main_next = "No Schedule"
                    self.main_state = 1
                elif (row[8] == 2):
                    self.main_explain = "[color=#19df07]- Manuale -[/color]"
                    self.main_setTemp = str(round(row[10],1))
                    self.main_next = ""
                    self.main_state = 2
                elif (row[8] == 3):
                    self.main_explain = "[color=#fcef55]- NoIce -[/color]"
                    self.main_setTemp = str(round(row[2],1))
                    self.main_next = ""
                    self.main_state = 3
                else :
                    self.main_setTemp = "OFF"
                    self.main_next = ""
                    self.main_state = 10

            self.remove_widget(self.dhtview)
            self.remove_widget(self.releview)
            self.dhtview.disegna_schermo()
            self.releview.disegna_schermo()
            self.tempgraph.graph() 
Example 45
Project: Thermostat_v5   Author: jpnos26   File: thermostat.py    MIT License 4 votes vote down vote up
def crono(self,*args):
        with thermostatLock:
            self.summer_time = time.strftime("%H : %M").lower()
            self.summer_date = time.strftime("%d - %B - %Y").lower()
            self.summer_explain = ""
            self.summer_state == 0
            data_summer = con.execute("select * from data where Id == 1")
            for row in data_summer.fetchall():
                if (row[5] != None):
                    self.summer_umidita = str(int(row[5]))+" % - "+str(int(row[6]))+" mBar"
                else:
                    self.summer_umidita =""
                if row[4] > row[14]:
                    self.summer_tendenza = "web/images/tendenzasu1.png"
                #elif (row[14] >= 0.31):
                #    self.main_tendenza = "web/images/tendenzasu2.png"
                elif (row[4] < row[14]):
                    self.summer_tendenza = "web/images/tendenzagiu1.png"
                #elif (row[14] <= -0.31):
                #    self.main_tendenza = "web/images/tendenzagiu2.png"
                else:
                    self.summer_tendenza = "web/images/tendenzauguale.png"
                if row[4] == 100:
                    self.summer_temp.text = "-.-"
                else:
                    self.summer_temp.text = str(round(row[4],1))+"°"
                self.slider_color = row[1]
                if (row[5] != None):
                    self.summer_umidita = str(int(row[5]))+" % - "+str(int(row[6]))+" mBar"
                else:
                    self.summer_umidita =""
                self.summer_temp.text = str(row[4])+"°"
                self.slider_color = row[1]
                if (row[8] == 1):
                    self.summer_setTemp = str(round(row[3],1))
                    self.summer_state = 1
                    try:
                        self.summer_explain = "[color=#fca62c]- Auto -[/color]"
                        self.summer_next = "[size=12] {:0>2d}".format(schedule.next_run().hour)+":"+"{:0>2d}".format(schedule.next_run().minute)+" --> "+str(min(schedule.jobs))[str(min(schedule.jobs)).find("(")+1:str(min(schedule.jobs)).find(")")]+"[/size]"
                    except:
                        self.summer_next = "No Schedule"
                    self.summer_state = 1
                elif (row[8] == 2):
                    self.summer_explain = "[color=#19df07]- Manuale -[/color]"
                    self.summer_setTemp = str(round(row[10],1))
                    self.summer_next = ""
                    self.summer_state = 2
                elif (row[8] == 3):
                    self.summer_explain = "[color=#fcef55]- NoIce -[/color]"
                    self.summer_setTemp = str(round(row[2],1))
                    self.summer_next = ""
                    self.summer_state = 3
                else :
                    self.summer_setTemp = "OFF"
                    self.summer_next = ""
                    self.summer_state = 10
            self.remove_widget(self.dhtview)
            self.remove_widget(self.releview)
            self.dhtview.disegna_schermo()
            self.releview.disegna_schermo()
            self.tempgraph.graph()