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


Python Arrow.now方法代码示例

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


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

示例1: get_for

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def get_for(date):
    date = date.replace(tzinfo='utc')
    for week in get_dates(access_token):
        for day, visits in week:
            if day == date:
                return VisitResult(
                    visits,      # visits for day
                    Arrow.now(AU_PERTH)  # when data was retrieved
                )
    return VisitResult([], Arrow.now(AU_PERTH))
开发者ID:Mause,项目名称:parkd,代码行数:12,代码来源:server.py

示例2: cached_get_for

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def cached_get_for(date):
    if not hasattr(cached_get_for, '_cache'):
        cached_get_for._cache = {}

    if date in cached_get_for._cache:
        data, timestamp = cached_get_for._cache[date]

        if (Arrow.now() - timestamp) < timedelta(hours=1):
            return data

    cached_get_for._cache[date] = (get_for(date), Arrow.now())
    return cached_get_for._cache[date][0]
开发者ID:Mause,项目名称:parkd,代码行数:14,代码来源:server.py

示例3: now

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def now(tz=None):
    '''Returns an :class:`Arrow <arrow.Arrow>` object, representing "now".

    :param tz: (optional) An expression representing a timezone.  Defaults to local time.

    Recognized timezone expressions:

        - A **tzinfo** object
        - A **str** describing a timezone, similar to "US/Pacific", or "Europe/Berlin"
        - A **str** in ISO-8601 style, as in "+07:00"
        - A **str**, one of the following:  *local*, *utc*, *UTC*

    Usage::

        >>> import arrow
        >>> arrow.now()
        <Arrow [2013-05-07T22:19:11.363410-07:00]>

        >>> arrow.now('US/Pacific')
        <Arrow [2013-05-07T22:19:15.251821-07:00]>

        >>> arrow.now('+02:00')
        <Arrow [2013-05-08T07:19:25.618646+02:00]>

        >>> arrow.now('local')
        <Arrow [2013-05-07T22:19:39.130059-07:00]>
    '''

    if tz is None:
        tz = dateutil_tz.tzlocal()
    elif not isinstance(tz, tzinfo):
        tz = parser.TzinfoParser.parse(tz)

    return Arrow.now(tz)
开发者ID:gurglet,项目名称:arrow,代码行数:36,代码来源:api.py

示例4: get_uptime

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def get_uptime(message):
    """
    Get uptime, code reload time and crash counts this session
    Usage: uptime
    """
    now = Arrow.now()
    reply('''{}

Way status:
    [ ] Lost
    [X] Not lost

Holding on since:
    {}
Uptime:
    {}
Last code reload:
    {}
Code uptime:
    {}

Total crashes this session: {}
    '''.format(
        VERSION_STRING,
        uptime.humanize(),
        now - uptime,
        code_uptime.humanize(),
        now - code_uptime,
        crash_count
    ), message)
开发者ID:K900,项目名称:m5,代码行数:32,代码来源:uptime.py

示例5: get_xml

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def get_xml(item, items):
    root = ET.Element('rss')
    root.attrib = {'version': "2.0"}
    c = ET.SubElement(root, 'channel')
    ET.SubElement(c, 'copyright').text = 'Copyright 2016, Liu Vaayne'
    if item.get('source_name') == 'wx':
        ET.SubElement(c, 'title').text = item.get('author')
    else:
        ET.SubElement(c, 'title').text = item.get('title')
    ET.SubElement(c, 'link').text = item.get('link')
    ET.SubElement(c, 'description').text = item.get('desc')
    ET.SubElement(c, 'lastBuildDate').text = Arrow.now().format('YYYY-MM-DD HH:mm:ss')
    for item in items:
        i = ET.SubElement(c, 'item')
        ET.SubElement(i, 'title').text = item.get('title')
        # ET.SubElement(i, 'image').text = item.get('image')
        # ET.SubElement(i, 'pubDate').text = datetime.datetime.fromtimestamp(int(item.get('post_time')))
        ET.SubElement(i, 'pubDate').text = item.get('post_time').strftime('%Y-%m-%d %H:%M:%S')
        ET.SubElement(i, 'link').text = item.get('source_url')
        # ET.SubElement(i, 'summary').text = item.get('summary')
        # ET.SubElement(i, 'description').text = item.get('content')
        ET.SubElement(i, 'category').text = item.get('category')
    tree = ET.ElementTree(root)
    f = StringIO()
    tree.write(sys.stdout)
    print (f.getvalue())
    return f.getvalue()
开发者ID:Vaayne,项目名称:vaayne.com,代码行数:29,代码来源:__init__.py

示例6: now

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def now(tz=None):
    '''Returns an :class:`Arrow <arrow.Arrow>` object, representing "now".

    :param tz: (optional) An expression representing a timezone.  Defaults to local time.

    The timezone expression can be:

        - A tzinfo struct
        - A string description, e.g. "US/Pacific", or "Europe/Berlin"
        - An ISO-8601 string, e.g. "+07:00"
        - A special string, one of:  "local", "utc", or "UTC"

    Usage::

        >>> import arrow
        >>> arrow.now()
        <Arrow [2013-05-07T22:19:11.363410-07:00]>
        >>> arrow.now('US/Pacific')
        <Arrow [2013-05-07T22:19:15.251821-07:00]>
        >>> arrow.now('+02:00')
        <Arrow [2013-05-08T07:19:25.618646+02:00]>
        >>> arrow.now('local')
        <Arrow [2013-05-07T22:19:39.130059-07:00]>
    '''

    if tz is None:
        tz = dateutil_tz.tzlocal()
    elif not isinstance(tz, tzinfo):
        tz = parser.TzinfoParser.parse(tz)

    return Arrow.now(tz)
开发者ID:pborreli,项目名称:arrow,代码行数:33,代码来源:api.py

示例7: get_course_list

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
 def get_course_list(self):
     # 获取课程状态
     if not self.__session:
         raise AttributeError('未获取有效的session对象')  # TODO 此sesseion判断并不严谨,需更改
     result = []
     now = int(Arrow.now().float_timestamp * 1000)  # generate javascript style timestamp
     _response = self.__session.get(
         'http://www.elearning.clic/ilearn/en/cst_learner2/jsp/home_my_course.jsp?_={time}'.format(
             time=now))  # 取得课程信息
     root = etree.HTML(_response.text)
     td_list = root.xpath(u'//span[@class="td_td_style"]')  # 查找有效表格
     a_list = root.xpath(u'//a[@title="Click to study"]')  # 查找有效课程url
     td_len = len(td_list)  # 取得有效td元素个数
     a_len = len(a_list)  # 取得有效链接个数
     if td_len is not 0 and a_len is not 0:
         # 如果找到有效td元素和a元素,就以每4组td生成一个字典
         for n in range(int(td_len / 4)):
             sub = 0 * n
             result.append({
                 'course_name': td_list[sub].text.strip(),
                 'course_section_rate': float(td_list[sub + 1].text.strip().partition('\n')[0]),
                 'course_time_rate': float(td_list[sub + 2].text.strip().partition('\n')[0]),
                 'course_finished': td_list[sub + 3].text.strip() == '已完成',
                 'course_url': a_list[n].attrib['href']
             })
     self.last_response = _response
     self.__course = result
     for k, v in enumerate(result):
         print('序号:{0} \t课名: {1}\t课程进度: {2}\t课时进度: {3}\t完成: {4}\n'.format(k, v['course_name'],
                                                                          v['course_section_rate'],
                                                                          v['course_time_rate'],
                                                                          v['course_finished'] is True))
开发者ID:evelive3,项目名称:elearning,代码行数:34,代码来源:learning.py

示例8: get_time_humanized

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
 def get_time_humanized(self):
     now = self.created
     otherdate = datetime.now()
     if otherdate:
         dt = otherdate - now
         offset = dt.seconds + (dt.days * 60*60*24)
     if offset:
         delta_s = offset % 60
         offset /= 60
         delta_m = offset % 60
         offset /= 60
         delta_h = offset % 24
         offset /= 24
         delta_d = offset
     else:
         return "just now"
     if delta_h > 1:
         return Arrow.now().replace(hours=delta_h * -1, minutes=delta_m * -1).humanize()
     if delta_m > 1:
         return Arrow.now().replace(seconds=delta_s * -1, minutes=delta_m * -1).humanize()
     else:
         return Arrow.now().replace(days=delta_d * -1).humanize()
开发者ID:ModulousSmash,项目名称:Modulous-Legacy,代码行数:24,代码来源:objects.py

示例9: save_course

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
 def save_course(self):
     # 保存课时
     save_data = {
         'callCount': 1,
         'page': '/ilearn/en/learner/jsp/player/player_left.jsp?rco_id={0}'.format(self.__save_dict.get('rco_id')),
         'httpSessionId': self.last_response.cookies.get('JSESSIONID'),
         'scriptSessionId': self.__script_session_id,
         'c0-scriptName': 'lessonStudyData',
         'c0-methodName': 'updateRcoTreeList',
         'c0-id': 0,
         'c0-e1': 'string:' + self.__save_dict.get('rco_id'),
         'c0-e2': 'string:' + self.__save_dict.get('curr_rco_id'),
         'c0-e3': 'string:' + self.__save_dict.get('curr_rco_id'),
         'c0-e4': 'string:' + self.__save_dict.get('icr_id'),
         'c0-e5': 'string:' + self.__save_dict.get('user_id'),
         'c0-e6': 'string:' + self.__save_dict.get('tbc_id'),
         'c0-e7': 'string:' + self.__save_dict.get('site_id'),
         'c0-e8': 'string:' + self.__save_dict.get('cmi_core_lesson_status'),
         'c0-e9': 'string:' + self.__save_dict.get('cmi_core_score_raw'),
         'c0-e10': 'string:' + self.__save_dict.get('cmi_core_lesson_location'),
         'c0-e11': 'string:' + self.__save_dict.get('cmi_suspend_data'),
         'c0-e12': 'string:' + self.__save_dict.get('cmi_core_session_time'),
         'c0-e13': 'string:' + self.__save_dict.get('cmi_mastery_score'),
         'c0-e14': 'string:' + self.__save_dict.get('cmi_core_credit'),
         'c0-e15': 'string:' + quote(self.__save_dict.get('start_time')),
         'c0-e16': 'string:' + quote(Arrow.now().isoformat(sep='\u0020').split('.')[0]),
         'c0-e17': 'string:' + self.__save_dict.get('pre_score'),
         'c0-e18': 'string:' + self.__save_dict.get('pre_status'),
         'c0-e19': 'string:' + self.__save_dict.get('pre_location'),
         'c0-e20': 'string:' + self.__save_dict.get('pre_suspend_data'),
         'c0-e21': 'string:' + self.__save_dict.get('effectivelength'),
         'c0-e22': 'string:' + self.__save_dict.get('is_lesson_time'),
         'c0-e23': 'string:' + self.__save_dict.get('tracking_type'),
         'c0-e24': 'string:' + self.__save_dict.get('attempt_num_flag'),
         'c0-param0': 'Object_Object:{rco_id:reference:c0-e1, pre_rco_id:reference:c0-e2, curr_rco_id:reference:c0-e3, icr_id:reference:c0-e4, user_id:reference:c0-e5, tbc_id:reference:c0-e6, site_id:reference:c0-e7, cmi_core_lesson_status:reference:c0-e8, cmi_core_score_raw:reference:c0-e9, cmi_core_lesson_location:reference:c0-e10, cmi_suspend_data:reference:c0-e11, cmi_core_session_time:reference:c0-e12, cmi_mastery_score:reference:c0-e13, cmi_core_credit:reference:c0-e14, start_time:reference:c0-e15, start_study_time:reference:c0-e16, pre_score:reference:c0-e17, pre_status:reference:c0-e18, pre_location:reference:c0-e19, pre_suspend_data:reference:c0-e20, effectivelength:reference:c0-e21, is_lesson_time:reference:c0-e22, tracking_type:reference:c0-e23, attempt_num_flag:reference:c0-e24}',
         'c0-param1': 'string:U',
         'batchId': self.__batch_id
     }
     self.__batch_id += 1
     _response = self.__session.post(
         'http://www.elearning.clic/ilearn/dwr/call/plaincall/lessonStudyData.updateRcoTreeList.dwr',
         save_data)
     self.last_response = _response
开发者ID:evelive3,项目名称:elearning,代码行数:45,代码来源:learning.py

示例10: get_date_from_request

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def get_date_from_request():
    date = request.args.get('date')

    if date is not None:
        try:
            date = get_date(date)
        except (ValueError, TypeError, ParserError):
            pass

    if date == 'today':
        date = Arrow.now(AU_PERTH)

    if date is not None:
        try:
            date = date.floor('day')
        except AttributeError:
            # was invalid and stayed a string
            date = None

    return date
开发者ID:Mause,项目名称:parkd,代码行数:22,代码来源:server.py

示例11: index

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def index():
    date = get_date_from_request()

    if date is None:
        # fill in missing values with defaults
        return redirect(url_for('.index', date='today'))

    visits, updated = get_visits_for_date(date)
    visits = sorted(visits.items())
    is_today = date.date() == Arrow.now(AU_PERTH).date()

    return render_template(
        'index.html',
        date=date,
        visits=visits,
        locations=LOCATIONS,
        updated=updated,
        is_today=is_today,
        next_page=make_link(date + ONE_DAY),
        prev_page=make_link(date - ONE_DAY)
    )
开发者ID:Mause,项目名称:parkd,代码行数:23,代码来源:server.py

示例12: get

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
def get(*args, **kwargs):
    '''Returns an :class:`Arrow <arrow.Arrow>` object based on flexible inputs.

    Usage::

        >>> import arrow

    **No inputs** to get current UTC time::

        >>> arrow.get()
        <Arrow [2013-05-08T05:51:43.316458+00:00]>

    **One str**, **float**, or **int**, convertible to a floating-point timestamp, to get that timestamp in UTC::

        >>> arrow.get(1367992474.293378)
        <Arrow [2013-05-08T05:54:34.293378+00:00]>

        >>> arrow.get(1367992474)
        <Arrow [2013-05-08T05:54:34+00:00]>

        >>> arrow.get('1367992474.293378')
        <Arrow [2013-05-08T05:54:34.293378+00:00]>

        >>> arrow.get('1367992474')
        <Arrow [2013-05-08T05:54:34+00:00]>

    **One str**, convertible to a timezone, or **tzinfo**, to get the current time in that timezone::

        >>> arrow.get('local')
        <Arrow [2013-05-07T22:57:11.793643-07:00]>

        >>> arrow.get('US/Pacific')
        <Arrow [2013-05-07T22:57:15.609802-07:00]>

        >>> arrow.get('-07:00')
        <Arrow [2013-05-07T22:57:22.777398-07:00]>

        >>> arrow.get(tz.tzlocal())
        <Arrow [2013-05-07T22:57:28.484717-07:00]>

    **One** naive **datetime**, to get that datetime in UTC::

        >>> arrow.get(datetime(2013, 5, 5))
        <Arrow [2013-05-05T00:00:00+00:00]>

    **One** aware **datetime**, to get that datetime::

        >>> arrow.get(datetime(2013, 5, 5, tzinfo=tz.tzlocal()))
        <Arrow [2013-05-05T00:00:00-07:00]>

    **Two** arguments, a naive or aware **datetime**, and a timezone expression (as above)::

        >>> arrow.get(datetime(2013, 5, 5), 'US/Pacific')
        <Arrow [2013-05-05T00:00:00-07:00]>

    **Two** arguments, both **str**, to parse the first according to the format of the second::

        >>> arrow.get('2013-05-05 12:30:45', 'YYYY-MM-DD HH:mm:ss')
        <Arrow [2013-05-05T12:30:45+00:00]>

    **Three or more** arguments, as for the constructor of a **datetime**::

        >>> arrow.get(2013, 5, 5, 12, 30, 45)
        <Arrow [2013-05-05T12:30:45+00:00]>
    '''

    arg_count = len(args)

    if arg_count == 0:
        return Arrow.utcnow()

    if arg_count == 1:
        arg = args[0]
        timestamp = None

        try:
            timestamp = float(arg)
        except:
            pass

        # (int), (float), (str(int)) or (str(float)) -> from timestamp.
        if timestamp is not None:
            return Arrow.utcfromtimestamp(timestamp)

        # (datetime) -> from datetime.
        elif isinstance(arg, datetime):
            return Arrow.fromdatetime(arg)

        # (tzinfo) -> now, @ tzinfo.
        elif isinstance(arg, tzinfo):
            return Arrow.now(arg)

        # (str) -> now, @ tzinfo.
        elif isinstance(arg, str):
            _tzinfo = parser.TzinfoParser.parse(arg)
            return Arrow.now(_tzinfo)

        else:
            raise TypeError('Can\'t parse single argument type of \'{0}\''.format(type(arg)))

#.........这里部分代码省略.........
开发者ID:gurglet,项目名称:arrow,代码行数:103,代码来源:api.py

示例13: crash

# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import now [as 别名]
from arrow import Arrow
from m5.core.dispatcher import on
from m5.core.event.messaging import reply
from m5.core.meta import VERSION_STRING
from m5.plugins.command_dispatcher import command

try:
    # noinspection PyUnboundLocalVariable,PyUnresolvedReferences
    uptime
except NameError:
    uptime = Arrow.now()

try:
    # noinspection PyUnboundLocalVariable
    crash_count
except NameError:
    crash_count = 0

code_uptime = Arrow.now()


@on('crash')
def crash(_):
    global crash_count
    crash_count += 1


@command('uptime')
def get_uptime(message):
    """
    Get uptime, code reload time and crash counts this session
开发者ID:K900,项目名称:m5,代码行数:33,代码来源:uptime.py


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