def time_before(self, time):
     kwargs = dict((k, getattr(self, k)) for k in self._time_attrs)
     t = time.replace(**kwargs)
     if t > time:
         previous_time = t - self.repeat_interval
     else:
         previous_time = t
     return previous_time
def update_attribute(id:str) -> Response:
    try:
        request_payload = request.get_json()
    except BadRequest as error:
        response = make_response(
            jsonify({"error": str(error)}), 400)
        return response

    try:
        g.data.update_attribute(id, request_payload)
    except ValueError as error:
        response = make_response(
            jsonify({"error": str(error)}), 400)
        return response
    else:
        response = make_response(
            jsonify({"message": "Team attribute updated."}), 201)
        return response

    time.replace(hour=7,minute=30,tzinfo=time.tzinfo)
Ejemplo n.º 3
0
def round_to_quarter(time):
    minutes_quarter = int(round((time.minute/60.)*4)/4*60)
    minutes_ten = int(round(time.minute/10.)*10)
    if abs(minutes_quarter-time.minute) < abs(minutes_ten-time.minute):
        minutes = minutes_quarter
    else:
        minutes = minutes_ten

    hours = time.hour
    if minutes == 60:
        minutes = 0
        hours += 1
    time = time.replace(hour=hours,minute=minutes)

    return time
Ejemplo n.º 4
0
Archivo: dates.py Proyecto: eavae/mlang
def format_time(time=None, format='medium', tzinfo=None, locale=LC_TIME):
    r"""Return a time formatted according to the given pattern.

    >>> t = time(15, 30)
    >>> format_time(t, locale='en_US')
    u'3:30:00 PM'
    >>> format_time(t, format='short', locale='de_DE')
    u'15:30'

    If you don't want to use the locale default formats, you can specify a
    custom time pattern:

    >>> format_time(t, "hh 'o''clock' a", locale='en')
    u"03 o'clock PM"

    For any pattern requiring the display of the time-zone a
    timezone has to be specified explicitly:

    >>> t = datetime(2007, 4, 1, 15, 30)
    >>> tzinfo = get_timezone('Europe/Paris')
    >>> t = tzinfo.localize(t)
    >>> format_time(t, format='full', tzinfo=tzinfo, locale='fr_FR')
    u'15:30:00 heure avanc\xe9e d\u2019Europe centrale'
    >>> format_time(t, "hh 'o''clock' a, zzzz", tzinfo=get_timezone('US/Eastern'),
    ...             locale='en')
    u"09 o'clock AM, Eastern Daylight Time"

    As that example shows, when this function gets passed a
    ``datetime.datetime`` value, the actual time in the formatted string is
    adjusted to the timezone specified by the `tzinfo` parameter. If the
    ``datetime`` is "naive" (i.e. it has no associated timezone information),
    it is assumed to be in UTC.

    These timezone calculations are **not** performed if the value is of type
    ``datetime.time``, as without date information there's no way to determine
    what a given time would translate to in a different timezone without
    information about whether daylight savings time is in effect or not. This
    means that time values are left as-is, and the value of the `tzinfo`
    parameter is only used to display the timezone name if needed:

    >>> t = time(15, 30)
    >>> format_time(t, format='full', tzinfo=get_timezone('Europe/Paris'),
    ...             locale='fr_FR')
    u'15:30:00 heure normale de l\u2019Europe centrale'
    >>> format_time(t, format='full', tzinfo=get_timezone('US/Eastern'),
    ...             locale='en_US')
    u'3:30:00 PM Eastern Standard Time'

    :param time: the ``time`` or ``datetime`` object; if `None`, the current
                 time in UTC is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param tzinfo: the time-zone to apply to the time for display
    :param locale: a `Locale` object or a locale identifier
    """
    if time is None:
        time = datetime.utcnow()
    elif isinstance(time, number_types):
        time = datetime.utcfromtimestamp(time)
    if time.tzinfo is None:
        time = time.replace(tzinfo=UTC)
    if isinstance(time, datetime):
        if tzinfo is not None:
            time = time.astimezone(tzinfo)
            if hasattr(tzinfo, 'normalize'): # pytz
                time = tzinfo.normalize(time)
        time = time.timetz()
    elif tzinfo is not None:
        time = time.replace(tzinfo=tzinfo)

    locale = Locale.parse(locale)
    if format in ('full', 'long', 'medium', 'short'):
        format = get_time_format(format, locale=locale)
    return parse_pattern(format).apply(time, locale)
Ejemplo n.º 5
0
allmatches = re.findall(regex, mystring)
mydict = {}

# Get initial timecode values
init_timecode = re.search(r'(\d\d):(\d\d):(\d\d):',allmatches[0])
starthour = int(init_timecode.group(1))
startminute = int(init_timecode.group(2))
startsecond = int(init_timecode.group(3))

for time in allmatches:
    timecode = datetime.datetime.strptime(time, "%H:%M:%S:%f")
    starttime = datetime.timedelta(days=0,hours=starthour,minutes=startminute,seconds=startsecond,milliseconds=0)
    newtime = timecode - starttime
    newformatted = newtime.strftime("%H:%M:%S,%f")[:-3]
    mydict[time] = time.replace(time, newformatted)

for k, v in mydict.iteritems():
    # This var now contains all of the cleaned up content thus far
    mystring = mystring.replace(k, v)

## Cleanup part 2: add a delay to each end time
regex2 = re.compile('(\d\d:\d\d:\d\d,\d\d\d) --> (\d\d:\d\d:\d\d,\d\d\d)')

allmatches2 = re.findall(regex2, mystring)
mydict2 = {}

for index, element in enumerate(allmatches2):
    end = element[1]
    next_start = allmatches2[(index + 1) % len(allmatches2)][0]
    end_time = datetime.datetime.strptime(end, "%H:%M:%S,%f")
Ejemplo n.º 6
0
def parser(text):

    for index, line in enumerate(text):
        i = 1 #all the lines are always in same order, so increasing i is only thing what we have to do
        #starting point might be bit unknown at first
        if '<td><a' in line:
            #klid is kauppalehti's own id, that we are used to mine their day that from that specific stock
            klid = line[line.rfind('klid='):]
            klid = klid[:klid.rfind('"')]
            klid = int(klid.replace('klid=', ''))
            
            print klid
            
            #name is stocks name
            name = line[line.rfind('">'):]
            name = name.replace('</a></td>', '')
            name = name.replace('">', '')
            
            #sometimes there are few stocks that don't have a name
            if name == '-':
                name = None
                
            #python doesn't like always Finnish letters, so lets cheat a little    
            if '\xc3\xa4' in name:
                name = name.replace('\xc3\xa4', "'a'")
            if '\xc3\xb6' in name:
                name = name.replace('\xc3\xb6', "'o'")
            if '\xc3\x85' in name:
                name = name.replace('\xc3\x85', "'OA'")
            print name
            
            #price line is next thing in a list
            priceLine = text[index+i]
            i += 1
            
            price = priceLine[priceLine.rfind('">'):]
            price = price.replace('</td>', '')
            price = price.replace('">', '')
            if price == '-':
                price = None
            else:
                price = Decimal(price)
            print price
            
            changeLine = text[index+i]
            i += 1
            #sometimes there is only newline in here, so we have to try nest list item
            if not changeLine.isalpha():
                changeLine = text[index+i]
                i += 1
                
            change = changeLine[changeLine.rfind('">'):]
            change = change.replace('</td>', '')
            change = change.replace('">', '')
            if change == '-':
                change = None
            print change
            
            timeLine = text[index+i]
            i += 1
            
            time = timeLine[timeLine.rfind('">'):]
            time = time.replace('</td>', '')
            time = time.replace('">', '')
            if time == '-':
                time = None
            print time
            
            buyLine = text[index+i]
            i += 1
            
            buy = buyLine[buyLine.rfind('tasot">'):]
            buy = buy.replace('</a></td>', '')
            buy = buy.replace('tasot">', '')
            if buy == '-':
                buy = None
            else:
                buy = Decimal(buy)
            print buy
            
            sellLine = text[index+i]
            i += 1
            
            sell = sellLine[sellLine.rfind('tasot">'):]
            sell = sell.replace('</a></td>', '')
            sell = sell.replace('tasot">', '')
            if sell == '-':
                sell = None
            else:
                sell = Decimal(sell)
            print sell
            
            highLine = text[index+i]
            i += 1
            
            high = highLine[highLine.rfind('">'):]
            high = high.replace('</td>', '')
            high = high.replace('">', '')
            if high == '-':
                high = None
            else:
                high = Decimal(high)
            print high
            
            ssellLine = text[index+i]
            i += 1
            
            ssell = ssellLine[ssellLine.rfind('">'):]
            ssell = ssell.replace('</td>', '')
            ssell = ssell.replace('">', '')
            if ssell == '-':
                ssell = None
            else:
                ssell = Decimal(ssell)
            print ssell
            
            volumeLine = text[index+i]
            i += 1
            
            volume = volumeLine[volumeLine.rfind('t">'):]
            volume = volume.replace('</a></td>', '')
            volume = volume.replace('t">', '')
            if volume == '-':
                volume = None
            else:
                volume = int(volume)
            print volume
            
            exchangeLine = text[index+i]
            i += 1
            
            exchange = exchangeLine[exchangeLine.rfind('">'):]
            exchange = exchange.replace('</td>', '')
            exchange = exchange.replace('">', '')
            if exchange == '-':
                exchange = None
            print exchange
            
            
            return {'name': name, "rise": change, 'price': price, 'buy': buy, 'sell': sell,
                    'lowest sell': ssell, 'high': high, 'volume': volume, 'exchange': exchange, 'time': time, 'klid': klid}   
Ejemplo n.º 7
0
def format_time(time=None, format="medium", tzinfo=None, locale=LC_TIME):
    r"""Return a time formatted according to the given pattern.

    >>> t = time(15, 30)
    >>> format_time(t, locale='en_US') == '3:30:00 PM'
    True
    >>> format_time(t, format='short', locale='de_DE') == '15:30'
    True

    If you don't want to use the locale default formats, you can specify a
    custom time pattern:

    >>> format_time(t, "hh 'o''clock' a", locale='en') == "03 o'clock PM"
    True

    For any pattern requiring the display of the time-zone, the third-party
    ``pytz`` package is needed to explicitly specify the time-zone:

    >>> from pytz import timezone
    >>> t = datetime(2007, 4, 1, 15, 30)
    >>> tzinfo = timezone('Europe/Paris')
    >>> t = tzinfo.localize(t)
    >>> format_time(t, format='full', tzinfo=tzinfo, locale='fr_FR') == '15:30:00 Heure avanc\xe9e de l\u2019Europe centrale'
    True
    >>> format_time(t, "hh 'o''clock' a, zzzz", tzinfo=timezone('US/Eastern'),
    ...             locale='en') == "09 o'clock AM, Eastern Daylight Time"
    True

    As that example shows, when this function gets passed a
    ``datetime.datetime`` value, the actual time in the formatted string is
    adjusted to the timezone specified by the `tzinfo` parameter. If the
    ``datetime`` is "naive" (i.e. it has no associated timezone information),
    it is assumed to be in UTC.

    These timezone calculations are **not** performed if the value is of type
    ``datetime.time``, as without date information there's no way to determine
    what a given time would translate to in a different timezone without
    information about whether daylight savings time is in effect or not. This
    means that time values are left as-is, and the value of the `tzinfo`
    parameter is only used to display the timezone name if needed:

    >>> t = time(15, 30)
    >>> format_time(t, format='full', tzinfo=timezone('Europe/Paris'),
    ...             locale='fr_FR') == '15:30:00 Heure normale de l\u2019Europe centrale'
    True
    >>> format_time(t, format='full', tzinfo=timezone('US/Eastern'),
    ...             locale='en_US') == '3:30:00 PM Eastern Standard Time'
    True

    :param time: the ``time`` or ``datetime`` object; if `None`, the current
                 time in UTC is used
    :param format: one of "full", "long", "medium", or "short", or a custom
                   date/time pattern
    :param tzinfo: the time-zone to apply to the time for display
    :param locale: a `Locale` object or a locale identifier
    :rtype: `unicode`

    :note: If the pattern contains date fields, an `AttributeError` will be
           raised when trying to apply the formatting. This is also true if
           the value of ``time`` parameter is actually a ``datetime`` object,
           as this function automatically converts that to a ``time``.
    """
    if time is None:
        time = datetime.utcnow()
    elif isinstance(time, (int, float)):
        time = datetime.utcfromtimestamp(time)
    if time.tzinfo is None:
        time = time.replace(tzinfo=UTC)
    if isinstance(time, datetime):
        if tzinfo is not None:
            time = time.astimezone(tzinfo)
            if hasattr(tzinfo, "normalize"):  # pytz
                time = tzinfo.normalize(time)
        time = time.timetz()
    elif tzinfo is not None:
        time = time.replace(tzinfo=tzinfo)

    locale = Locale.parse(locale)
    if format in ("full", "long", "medium", "short"):
        format = get_time_format(format, locale=locale)
    return parse_pattern(format).apply(time, locale)