当前位置: 首页>>代码示例>>Python>>正文


Python time.replace方法代码示例

本文整理汇总了Python中time.replace方法的典型用法代码示例。如果您正苦于以下问题:Python time.replace方法的具体用法?Python time.replace怎么用?Python time.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在time的用法示例。


在下文中一共展示了time.replace方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: onTick

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def onTick(self, d):
        """"""
        symbol = d['symbol']

        tick = self.tickDict.get(symbol, None)
        if not tick:
            return

        tick.lastPrice = d['price']

        date, time = str(d['timestamp']).split('T')
        tick.date = date.replace('-', '')
        tick.time = time.replace('Z', '')
        tick.datetime = datetime.now()

        self.gateway.onTick(tick)

    # ---------------------------------------------------------------------- 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:bitmexGateway.py

示例2: onDepth

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def onDepth(self, d):
        """"""
        symbol = d['symbol']
        tick = self.tickDict.get(symbol, None)
        if not tick:
            return

        for n, buf in enumerate(d['bids'][:5]):
            price, volume = buf
            tick.__setattr__('bidPrice%s' % (n + 1), price)
            tick.__setattr__('bidVolume%s' % (n + 1), volume)

        for n, buf in enumerate(d['asks'][:5]):
            price, volume = buf
            tick.__setattr__('askPrice%s' % (n + 1), price)
            tick.__setattr__('askVolume%s' % (n + 1), volume)

        date, time = str(d['timestamp']).split('T')
        tick.date = date.replace('-', '')
        tick.time = time.replace('Z', '')

        self.gateway.onTick(tick)

    # ---------------------------------------------------------------------- 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:bitmexGateway.py

示例3: historical_price

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def historical_price(request):
    fiat = request.GET['fiat'].upper()
    crypto = request.GET['currency'].upper()
    try:
        time = arrow.get(request.GET['time']).datetime
    except:
        return http.JsonResponse({'error': "Invalid Time argument"}, status=400)

    try:
        price = PriceTick.nearest(crypto, fiat, time)
    except PriceTick.DoesNotExist:
        return http.JsonResponse(
            {'error': "Can't get historical price for %s->%s" % (fiat, crypto)},
            status=400
        )

    try:
        naive_time = time.replace(tzinfo=None)
        price['estimated_supply'] = SupplyEstimator(crypto).calculate_supply(at_time=naive_time)
    except NotImplementedError:
        pass

    price['currency'] = crypto
    return http.JsonResponse(price) 
开发者ID:priestc,项目名称:MultiExplorer,代码行数:26,代码来源:views.py

示例4: __parse

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def __parse(value):
        """
        Parse the string date.

        Supports the subset of ISO8601 used by xsd:time, but is lenient with
        what is accepted, handling most reasonable syntax.

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

        @param value: A time string.
        @type value: str
        @return: A time object.
        @rtype: B{datetime}.I{time}

        """
        match_result = _RE_TIME.match(value)
        if match_result is None:
           raise ValueError("date data has invalid format '%s'" % (value,))

        time, round_up = _time_from_match(match_result)
        tzinfo = _tzinfo_from_match(match_result)
        if round_up:
            time = _bump_up_time_by_microsecond(time)
        return time.replace(tzinfo=tzinfo) 
开发者ID:suds-community,项目名称:suds,代码行数:27,代码来源:date.py

示例5: onTrade

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def onTrade(self, d):
        """"""
        if not d['lastQty']:
            return

        tradeID = d['execID']
        if tradeID in self.tradeSet:
            return
        self.tradeSet.add(tradeID)

        trade = VtTradeData()
        trade.gatewayName = self.gatewayName

        trade.symbol = d['symbol']
        trade.exchange = EXCHANGE_BITMEX
        trade.vtSymbol = '.'.join([trade.symbol, trade.exchange])
        if d['clOrdID']:
            orderID = d['clOrdID']
        else:
            orderID = d['orderID']
        trade.orderID = orderID
        trade.vtOrderID = '.'.join([trade.gatewayName, trade.orderID])

        trade.tradeID = tradeID
        trade.vtTradeID = '.'.join([trade.gatewayName, trade.tradeID])

        trade.direction = directionMapReverse[d['side']]
        trade.price = d['lastPx']
        trade.volume = d['lastQty']
        trade.tradeTime = d['timestamp'][0:22].replace('T', '')

        self.gateway.onTrade(trade)

    # ---------------------------------------------------------------------- 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:36,代码来源:bitmexGateway.py

示例6: onOrder

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def onOrder(self, d):
        """"""
        if 'ordStatus' not in d:
            return

        sysID = d['orderID']
        if sysID in self.orderDict:
            order = self.orderDict[sysID]
        else:
            order = VtOrderData()
            order.gatewayName = self.gatewayName

            order.symbol = d['symbol']
            order.exchange = EXCHANGE_BITMEX
            order.vtSymbol = '.'.join([order.symbol, order.exchange])

            if d['clOrdID']:
                orderID = d['clOrdID']
            else:
                orderID = sysID
            order.orderID = orderID
            order.vtOrderID = '.'.join([self.gatewayName, order.orderID])

            order.direction = directionMapReverse[d['side']]

            if d['price']:
                order.price = d['price']

            order.totalVolume = d['orderQty']
            order.orderTime = d['timestamp'][0:10].replace('-', '')

            self.orderDict[sysID] = order

        order.tradedVolume = d.get('cumQty', order.tradedVolume)
        order.status = statusMapReverse.get(d['ordStatus'], STATUS_UNKNOWN)

        self.gateway.onOrder(order)

        # ---------------------------------------------------------------------- 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:41,代码来源:bitmexGateway.py

示例7: faketime

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def faketime(module_name, *times):
    """Monkey patch datetime.now to return fake time."""

    class FakeDatetime:
        def __init__(self, times):
            self.times = times

        def __enter__(self):
            module = import_module(module_name)
            setattr(module.datetime, "datetime", self)

        def __exit__(self, exc_type, exc_val, exc_tb):
            module = import_module(module_name)
            setattr(module.datetime, "datetime", datetime)

        def now(self, tz=None):
            """Replace times from now to fake values."""
            if not self.time:
                return datetime.now(tz=tz)

            next_time = self.times[0]
            if len(self.times) > 1:
                self.times = self.times[1:]

            time = datetime.fromtimestamp(next_time)
            if tz:
                time = time.replace(tzinfo=tz)
            return time

        def __call__(self, *args, **kwargs):
            return datetime(*args, **kwargs)

        def __getattr__(self, attr):
            """Redirect non-stubbed functions to original module."""
            return getattr(datetime, attr)

    return FakeDatetime(list(times)) 
开发者ID:postlund,项目名称:pyatv,代码行数:39,代码来源:utils.py

示例8: get_titles_from_cards

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def get_titles_from_cards(cards):
    #PULLS TITLE DATA FROM EACH CARD IN CARDS, RETURNS A LIST OF TITLES
    def title_cleaner(title):
        #REMOVE MEDIUMS ENCODING SYMBOLS AND EMOJIS FROM TITLES
        title = title.replace("\xa0"," ")
        title = title.replace("\u200a","")
        title = title.replace("\ufe0f","")
        title = re.sub(r'[^\x00-\x7F]+','', title)
        return title

    titles=[]
    for card in cards:
        #SEARCH FOR TITLE THERE ARE 3 DIFF CLASSES
        variant1 = card.find("h3", class_="graf graf--h3 graf-after--figure graf--title")
        variant2 = card.find("h3", class_="graf graf--h3 graf-after--figure graf--trailing graf--title")
        variant3 = card.find("h4", class_="graf graf--h4 graf--leading")
        variant4 = card.find("h3", class_="graf graf--h3 graf--leading graf--title")
        variant5 = card.find("p", class_="graf graf--p graf--leading")
        variant6 = card.find("h3", class_="graf graf--h3 graf--startsWithDoubleQuote graf--leading graf--title")
        variant7= card.find("h3", class_="graf graf--h3 graf--startsWithDoubleQuote graf-after--figure graf--trailing graf--title")
        #EACH CARD MUST HAVE ONE OF THE ABOVE TITLE CLASSES FIND IT AND CUT OUT MEDIUM'S
        #STYLING CODES
        variants = [variant1, variant2, variant3, variant4, variant5, variant6, variant7]
        saved = False
        #THE FIRST TITLE ENTRY WE MATCH, WE SAVE
        for variant in variants:
            if ((variant is not None) and (not saved)):
                title = variant.text
                title = title_cleaner(title)
                titles.append(title)
                saved = True
        if not saved:
            titles.append("NaN")
    return titles 
开发者ID:harrisonjansma,项目名称:Medium_Scraper,代码行数:36,代码来源:medium_scraper.py

示例9: get_subtitles_from_cards

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def get_subtitles_from_cards(cards):
    #PULLS TITLE DATA FROM EACH CARD IN CARDS, RETURNS A LIST OF TITLES
    def subtitle_cleaner(subtitle):
        #REMOVE MEDIUMS ENCODING SYMBOLS AND EMOJIS FROM TITLES
        subtitle = subtitle.replace("\xa0"," ")
        subtitle = subtitle.replace("\u200a","")
        subtitle = subtitle.replace("\ufe0f","")
        subtitle = re.sub(r'[^\x00-\x7F]+','', subtitle)
        return subtitle

    subtitles=[]
    for card in cards:
        #SEARCH FOR TITLE THERE ARE 3 DIFF CLASSES
        variant1 = card.find("h4", class_="graf graf--h4 graf-after--h3 graf--subtitle")
        variant2 = card.find("h4", class_="graf graf--h4 graf-after--h3 graf--trailing graf--subtitle")
        variant3 = card.find("strong", class_="markup--strong markup--p-strong")
        variant4 = card.find("h4", class_="graf graf--p graf-after--h3 graf--trailing")
        variant5= card.find("p", class_="graf graf--p graf-after--h3 graf--trailing")
        variant6= card.find("blockquote", class_="graf graf--pullquote graf-after--figure graf--trailing")
        variant7 = card.find("p", class_="graf graf--p graf-after--figure")
        variant8 = card.find("blockquote", class_="graf graf--blockquote graf-after--h3 graf--trailing")
        variant9 = card.find("p", class_="graf graf--p graf-after--figure graf--trailing")
        variant10 = card.find("em", class_="markup--em markup--p-em")
        variant11=card.find("p", class_="graf graf--p graf-after--p graf--trailing")
        #EACH CARD MUST HAVE ONE OF THE TITLE CLASSES FIND IT AND CUT OUT MEDIUM'S
        #STYLING CODES
        variants = [variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11]
        saved = False
        for variant in variants:
            if ((variant is not None) and (not saved)):
                subtitle = variant.text
                subtitle = subtitle_cleaner(subtitle)
                subtitles.append(subtitle)
                saved = True
        if not saved:
            subtitles.append("NaN")
    return subtitles 
开发者ID:harrisonjansma,项目名称:Medium_Scraper,代码行数:39,代码来源:medium_scraper.py

示例10: get_readTime_from_cards

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def get_readTime_from_cards(cards):
    #PULL READTIME FROM EACH CARD IN CARDS
    readingTimes=[]
    for card in cards:
        time = card.find("span", class_="readingTime")
        if time is not None:
            time = time['title']
            time = time.replace(" min read", "")
            readingTimes.append(time)
        else:
            readingTimes.append("0")
    return readingTimes 
开发者ID:harrisonjansma,项目名称:Medium_Scraper,代码行数:14,代码来源:medium_scraper.py

示例11: __is_daylight_time

# 需要导入模块: import time [as 别名]
# 或者: from time import replace [as 别名]
def __is_daylight_time(self, dt):
        if not time.daylight:
            return False
        time_tuple = dt.replace(tzinfo=None).timetuple()
        time_tuple = time.localtime(time.mktime(time_tuple))
        return time_tuple.tm_isdst > 0 
开发者ID:suds-community,项目名称:suds,代码行数:8,代码来源:date.py


注:本文中的time.replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。