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


Python time.html方法代码示例

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


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

示例1: classify

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def classify(self, contents):
        """BosonNLP `新闻分类接口 <http://docs.bosonnlp.com/classify.html>`_ 封装。

        :param contents: 需要做分类的新闻文本或者文本序列。
        :type contents: string or sequence of string

        :returns: 接口返回的结果列表。

        :raises: :py:exc:`~bosonnlp.HTTPError` 如果 API 请求发生错误。

        调用示例:

        >>> import os
        >>> nlp = BosonNLP(os.environ['BOSON_API_TOKEN'])
        >>> nlp.classify('俄否决安理会谴责叙军战机空袭阿勒颇平民')
        [5]
        >>> nlp.classify(['俄否决安理会谴责叙军战机空袭阿勒颇平民',
        ...               '邓紫棋谈男友林宥嘉:我觉得我比他唱得好',
        ...               'Facebook收购印度初创公司'])
        [5, 4, 8]
        """
        api_endpoint = '/classify/analysis'
        r = self._api_request('POST', api_endpoint, data=contents)
        return r.json() 
开发者ID:bosondata,项目名称:bosonnlp.py,代码行数:26,代码来源:client.py

示例2: suggest

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def suggest(self, word, top_k=None):
        """BosonNLP `语义联想接口 <http://docs.bosonnlp.com/suggest.html>`_ 封装。

        :param string word: 需要做语义联想的词。

        :param int top_k: 默认为 10,最大值可设定为 100。返回的结果条数。

        :returns: 接口返回的结果列表。

        :raises: :py:exc:`~bosonnlp.HTTPError` 如果 API 请求发生错误。

        调用示例:

        >>> import os
        >>> nlp = BosonNLP(os.environ['BOSON_API_TOKEN'])
        >>> nlp.suggest('北京', top_k=2)
        [[1.0, '北京/ns'], [0.7493540460397998, '上海/ns']]
        """
        api_endpoint = '/suggest/analysis'
        params = {}
        if top_k is not None:
            params['top_k'] = top_k
        r = self._api_request('POST', api_endpoint, params=params, data=word)
        return r.json() 
开发者ID:bosondata,项目名称:bosonnlp.py,代码行数:26,代码来源:client.py

示例3: strptime

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def strptime(cls, string, format):
        """
        Constructs a :class:`mw.Timestamp` from an explicitly formatted string.
        See `<https://docs.python.org/3/library/time.html#time.strftime>`_ for a
        discussion of formats descriptors.

        :Parameters:
            string : str
                A formatted timestamp
            format : str
                The format description

        :Returns:
            :class:`mw.Timestamp`
        """
        return cls.from_time_struct(time.strptime(string, format)) 
开发者ID:mediawiki-utilities,项目名称:python-mediawiki-utilities,代码行数:18,代码来源:timestamp.py

示例4: DatetimeToUTCMicros

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def DatetimeToUTCMicros(date):
  """Converts a datetime object to microseconds since the epoch in UTC.

  Args:
    date: A datetime to convert.
  Returns:
    The number of microseconds since the epoch, in UTC, represented by the input
    datetime.
  """
  # Using this guide: http://wiki.python.org/moin/WorkingWithTime
  # And this conversion guide: http://docs.python.org/library/time.html

  # Turn the date parameter into a tuple (struct_time) that can then be
  # manipulated into a long value of seconds.  During the conversion from
  # struct_time to long, the source date in UTC, and so it follows that the
  # correct transformation is calendar.timegm()
  micros = calendar.timegm(date.utctimetuple()) * _MICROSECONDS_PER_SECOND
  return micros + date.microsecond 
开发者ID:google,项目名称:google-apputils,代码行数:20,代码来源:datelib.py

示例5: curtime

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def curtime(timeStr="%d.%m.%Y %H:%M:%S", timestamp=""):
	"""
	Returns formated date and/or time
	see: https://docs.python.org/2/library/time.html#time.strftime

	@type    format: string
	@param   format: Python time Format-String
	@type    timestamp: floating point number
	@param   timestamp: time in seconds since the epoch

	@return:    Formated Time and/or Date
	@exception: Exception if Error in format
	"""
	try:
		if timestamp == "":
			return time.strftime(timeStr)
		else:
			return time.strftime(timeStr, time.localtime(timestamp))
	except:
		logging.warning("error in time-format-string")
		logging.debug("error in time-format-string", exc_info=True) 
开发者ID:Schrolli91,项目名称:BOSWatch,代码行数:23,代码来源:timeHandler.py

示例6: AddShortTaskAbsolute

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def AddShortTaskAbsolute(self, startTime, func, *args, **kwargs):
        """
        This does the same as :meth:`AddShortTask`, but the `startTime` parameter
        specifies an absolute time expressed in floating point seconds since
        the epoch. Take a look at the documentation of `Python's time module`_,
        for more information about this time format. Again a little example::

            import time
            startTime = time.mktime((2007, 8, 15, 16, 53, 0, 0, 0, -1))
            eg.scheduler.AddShortTaskAbsolute(startTime, eg.TriggerEvent, "MyEvent")

        This will trigger the event "Main.MyEvent" at 16:53:00 on 15 August
        2007. If you run this code after this point of time, the
        :func:`eg.TriggerEvent` will be called immediately.

        .. _Python's time module: http://docs.python.org/lib/module-time.html
        """
        try:
            self.lock.acquire()
            task = (startTime, func, args, kwargs)
            heappush(self.heap, task)
            self.event.set()
        finally:
            self.lock.release()
        return task 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:27,代码来源:Scheduler.py

示例7: get_dhl_formatted_shipment_time

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def get_dhl_formatted_shipment_time(self):
        """
        Formats the shipment date and time in the DHL time format, including the UTC offset
        :return: formatted date time stamp
        """
        self.ship_datetime = self.ship_datetime or datetime.now()
        if not self.utc_offset:
            # time lib https://docs.python.org/3/library/time.html#time.strftime
            self.utc_offset = time.strftime('%z')  # just take the utc offset from the time lib
            self.utc_offset = self.utc_offset[:-2] + ':' + self.utc_offset[-2:]  # insert : in +0100 to get +01:00

        self.ship_datetime += timedelta(minutes=5)
        formatted_time = self.ship_datetime.strftime(self.dhl_datetime_format)
        return formatted_time + self.utc_offset 
开发者ID:benqo,项目名称:python-dhl,代码行数:16,代码来源:shipment.py

示例8: safe_sleep

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def safe_sleep(seconds):
  """Ensure that the thread sleeps at a minimum the requested seconds.

  Until Python 3.5, there was no guarantee that time.sleep() would actually sleep the requested
  time. See https://docs.python.org/3/library/time.html#time.sleep."""
  if sys.version_info[0:2] >= (3, 5):
    time.sleep(seconds)
  else:
    start_time = current_time = time.time()
    while current_time - start_time < seconds:
      remaining_time = seconds - (current_time - start_time)
      time.sleep(remaining_time)
      current_time = time.time() 
开发者ID:pantsbuild,项目名称:pex,代码行数:15,代码来源:common.py

示例9: finalize

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def finalize(self, source=None):
    """Rename `work_dir` to `target_dir` using `os.rename()`.

    :param str source: An optional source offset into the `work_dir`` to use for the atomic
                       update of `target_dir`. By default the whole `work_dir` is used.

    If a race is lost and `target_dir` already exists, the `target_dir` dir is left unchanged and
    the `work_dir` directory will simply be removed.
    """
    if self.is_finalized:
      return

    source = os.path.join(self._work_dir, source) if source else self._work_dir
    try:
      # Perform an atomic rename.
      #
      # Per the docs: https://docs.python.org/2.7/library/os.html#os.rename
      #
      #   The operation may fail on some Unix flavors if src and dst are on different filesystems.
      #   If successful, the renaming will be an atomic operation (this is a POSIX requirement).
      #
      # We have satisfied the single filesystem constraint by arranging the `work_dir` to be a
      # sibling of the `target_dir`.
      os.rename(source, self._target_dir)
    except OSError as e:
      if e.errno not in (errno.EEXIST, errno.ENOTEMPTY):
        raise e
    finally:
      self.cleanup() 
开发者ID:pantsbuild,项目名称:pex,代码行数:31,代码来源:common.py

示例10: consume

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def consume(self, subscription_name, callback, scheduler):
        """Begin listening to topic from the SubscriberClient.

        :param subscription_name: str Subscription name
        :param callback: Function which act on a topic message
        :param scheduler: `Thread pool-based scheduler.<https://googleapis.dev/python/pubsub/latest/subscriber/api/scheduler.html?highlight=threadscheduler#google.cloud.pubsub_v1.subscriber.scheduler.ThreadScheduler>`_  # noqa
        :return: `Future <https://googleapis.github.io/google-cloud-python/latest/pubsub/subscriber/api/futures.html>`_  # noqa
        """
        subscription_path = self._client.subscription_path(
            self._gc_project_id, subscription_name
        )
        return self._client.subscribe(
            subscription_path, callback=callback, scheduler=scheduler
        ) 
开发者ID:mercadona,项目名称:rele,代码行数:16,代码来源:client.py

示例11: sentiment

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def sentiment(self, contents, model='general'):
        """BosonNLP `情感分析接口 <http://docs.bosonnlp.com/sentiment.html>`_ 封装。

        :param contents: 需要做情感分析的文本或者文本序列。
        :type contents: string or sequence of string

        :param model: 使用不同语料训练的模型,默认使用通用模型。
        :type model: string

        :returns: 接口返回的结果列表。

        :raises: :py:exc:`~bosonnlp.HTTPError` 如果 API 请求发生错误。

        调用示例:

        >>> import os
        >>> nlp = BosonNLP(os.environ['BOSON_API_TOKEN'])
        >>> nlp.sentiment('这家味道还不错', model='food')
        [[0.9991737012037423, 0.0008262987962577828]]
        >>> nlp.sentiment(['这家味道还不错', '菜品太少了而且还不新鲜'], model='food')
        [[0.9991737012037423, 0.0008262987962577828],
         [9.940036427291687e-08, 0.9999999005996357]]
        """
        api_endpoint = '/sentiment/analysis?' + model
        r = self._api_request('POST', api_endpoint, data=contents)
        return r.json() 
开发者ID:bosondata,项目名称:bosonnlp.py,代码行数:28,代码来源:client.py

示例12: convert_time

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def convert_time(self, content, basetime=None):
        """BosonNLP `时间描述转换接口 <http://docs.bosonnlp.com/time.html>`_ 封装

        :param content: 中文时间描述字符串
        :type content: string

        :param basetime: 时间描述的基准时间,传入一个时间戳或datetime
        :type basetime: int or datetime.datetime

        :raises: :py:exc:`~bosonnlp.HTTPError` 如果 API 请求发生错误。

        :returns: 接口返回的结果

        调用示例:

        >>> import os
        >>> nlp = BosonNLP(os.environ['BOSON_API_TOKEN'])
        >>> _json_dumps(nlp.convert_time("2013年二月二十八日下午四点三十分二十九秒"))
        '{"timestamp": "2013-02-28 16:30:29", "type": "timestamp"}'
        >>> import datetime
        >>> _json_dumps(nlp.convert_time("今天晚上8点到明天下午3点", datetime.datetime(2015, 9, 1)))
        '{"timespan": ["2015-09-02 20:00:00", "2015-09-03 15:00:00"], "type": "timespan_0"}'

        """
        api_endpoint = '/time/analysis'
        params = {'pattern': content}
        if basetime:
            if isinstance(basetime, datetime.datetime):
                basetime = int(time.mktime(basetime.timetuple()))
            params['basetime'] = basetime
        r = self._api_request('POST', api_endpoint, params=params)
        return r.json() 
开发者ID:bosondata,项目名称:bosonnlp.py,代码行数:34,代码来源:client.py

示例13: extract_keywords

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def extract_keywords(self, text, top_k=None, segmented=False):
        """BosonNLP `关键词提取接口 <http://docs.bosonnlp.com/keywords.html>`_ 封装。

        :param string text: 需要做关键词提取的文本。

        :param int top_k: 默认为 100,返回的结果条数。

        :param bool segmented: 默认为 :py:class:`False`,`text` 是否已进行了分词,如果为
            :py:class:`True`,则不会再对内容进行分词处理。

        :returns: 接口返回的结果列表。

        :raises: :py:exc:`~bosonnlp.HTTPError` 如果 API 请求发生错误。

        调用示例:

        >>> import os
        >>> nlp = BosonNLP(os.environ['BOSON_API_TOKEN'])
        >>> nlp.extract_keywords('病毒式媒体网站:让新闻迅速蔓延', top_k=2)
        [[0.8391345017584958, '病毒式'], [0.3802418301341705, '蔓延']]
        """
        api_endpoint = '/keywords/analysis'
        params = {}
        if segmented:
            params['segmented'] = 1
        if top_k is not None:
            params['top_k'] = top_k
        r = self._api_request('POST', api_endpoint, params=params, data=text)
        return r.json() 
开发者ID:bosondata,项目名称:bosonnlp.py,代码行数:31,代码来源:client.py

示例14: sign

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def sign(username, private_key, generate_nonce=None, iat=None, algorithm=DEFAULT_ALGORITHM):
    """
    Create a signed JWT using the given username and RSA private key.

    :param username: Username (string) to authenticate as on the remote system.
    :param private_key: Private key to use to sign the JWT claim.
    :param generate_nonce: Optional. Callable to use to generate a new nonce. Defaults to
        `random.random <https://docs.python.org/3/library/random.html#random.random>`_.
    :param iat: Optional. Timestamp to include in the JWT claim. Defaults to
        `time.time <https://docs.python.org/3/library/time.html#time.time>`_.
    :param algorithm: Optional. Algorithm to use to sign the JWT claim. Default to ``RS512``.
        See `pyjwt.readthedocs.io <https://pyjwt.readthedocs.io/en/latest/algorithms.html>`_ for other possible algorithms.
    :return: JWT claim as a string.
    """
    iat = iat if iat else time.time()
    if not generate_nonce:
        generate_nonce = lambda username, iat: random.random()  # NOQA

    token_data = {
        'username': username,
        'time': iat,
        'nonce': generate_nonce(username, iat),
    }

    token = jwt.encode(token_data, private_key, algorithm=algorithm)
    return token 
开发者ID:crgwbr,项目名称:asymmetric-jwt-auth,代码行数:28,代码来源:token.py

示例15: strftime

# 需要导入模块: import time [as 别名]
# 或者: from time import html [as 别名]
def strftime(self, format):
        """
        Constructs a formatted string.
        See `<https://docs.python.org/3/library/time.html#time.strftime>`_ for a
        discussion of formats descriptors.

        :Parameters:
            format : str
                The format description

        :Returns:
            A formatted string
        """
        return time.strftime(format, self.__time) 
开发者ID:mediawiki-utilities,项目名称:python-mediawiki-utilities,代码行数:16,代码来源:timestamp.py


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