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


Python arrow.now方法代码示例

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


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

示例1: jinja2_filter

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def jinja2_filter(app):
    def format_datetime(value):
        dt = arrow.get(value)
        return dt.humanize()

    app.jinja_env.filters["dt"] = format_datetime

    @app.context_processor
    def inject_stage_and_region():
        return dict(
            YEAR=arrow.now().year,
            URL=URL,
            SENTRY_DSN=SENTRY_FRONT_END_DSN,
            VERSION=SHA1,
            FIRST_ALIAS_DOMAIN=FIRST_ALIAS_DOMAIN,
        ) 
开发者ID:simple-login,项目名称:app,代码行数:18,代码来源:server.py

示例2: notify_premium_end

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def notify_premium_end():
    """sent to user who has canceled their subscription and who has their subscription ending soon"""
    for sub in Subscription.query.filter(Subscription.cancelled == True).all():
        if (
            arrow.now().shift(days=3).date()
            > sub.next_bill_date
            >= arrow.now().shift(days=2).date()
        ):
            user = sub.user
            LOG.d(f"Send subscription ending soon email to user {user}")

            send_email(
                user.email,
                f"Your subscription will end soon {user.name}",
                render(
                    "transactional/subscription-end.txt",
                    user=user,
                    next_bill_date=sub.next_bill_date.strftime("%Y-%m-%d"),
                ),
                render(
                    "transactional/subscription-end.html",
                    user=user,
                    next_bill_date=sub.next_bill_date.strftime("%Y-%m-%d"),
                ),
            ) 
开发者ID:simple-login,项目名称:app,代码行数:27,代码来源:cron.py

示例3: handle_sender_email

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def handle_sender_email(envelope: Envelope):
    filename = (
        arrow.now().format("YYYY-MM-DD_HH-mm-ss") + "_" + random_string(10) + ".eml"
    )
    filepath = os.path.join(SENDER_DIR, filename)

    with open(filepath, "wb") as f:
        f.write(envelope.original_content)

    LOG.d("Write email to sender at %s", filepath)

    msg = email.message_from_bytes(envelope.original_content)
    orig = get_orig_message_from_bounce(msg)
    if orig:
        LOG.warning(
            "Original message %s -> %s saved at %s", orig["From"], orig["To"], filepath
        )

    return "250 email to sender accepted" 
开发者ID:simple-login,项目名称:app,代码行数:21,代码来源:email_handler.py

示例4: require_api_auth

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def require_api_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        if current_user.is_authenticated:
            g.user = current_user
        else:
            api_code = request.headers.get("Authentication")
            api_key = ApiKey.get_by(code=api_code)

            if not api_key:
                return jsonify(error="Wrong api key"), 401

            # Update api key stats
            api_key.last_used = arrow.now()
            api_key.times += 1
            db.session.commit()

            g.user = api_key.user

        return f(*args, **kwargs)

    return decorated 
开发者ID:simple-login,项目名称:app,代码行数:24,代码来源:base.py

示例5: _lifetime_or_active_subscription

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def _lifetime_or_active_subscription(self) -> bool:
        """True if user has lifetime licence or active subscription"""
        if self.lifetime:
            return True

        sub: Subscription = self.get_subscription()
        if sub:
            return True

        apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=self.id)
        if apple_sub and apple_sub.is_valid():
            return True

        manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=self.id)
        if manual_sub and manual_sub.end_at > arrow.now():
            return True

        return False 
开发者ID:simple-login,项目名称:app,代码行数:20,代码来源:models.py

示例6: can_upgrade

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def can_upgrade(self):
        """User who has lifetime licence or giveaway manual subscriptions can decide to upgrade to a paid plan"""
        sub: Subscription = self.get_subscription()
        # user who has canceled can also re-subscribe
        if sub and not sub.cancelled:
            return False

        apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=self.id)
        if apple_sub and apple_sub.is_valid():
            return False

        manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=self.id)
        # user who has giveaway premium can decide to upgrade
        if (
            manual_sub
            and manual_sub.end_at > arrow.now()
            and not manual_sub.is_giveaway
        ):
            return False

        return True 
开发者ID:simple-login,项目名称:app,代码行数:23,代码来源:models.py

示例7: get_subscription

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def get_subscription(self) -> "Subscription":
        """return *active* subscription
        TODO: support user unsubscribe and re-subscribe
        """
        sub = Subscription.get_by(user_id=self.id)
        # TODO: sub is active only if sub.next_bill_date > now
        # due to a bug on next_bill_date, wait until next month (May 8)
        # when all next_bill_date are correctly updated to add this check

        if sub and sub.cancelled:
            # sub is active until the next billing_date + 1
            if sub.next_bill_date >= arrow.now().shift(days=-1).date():
                return sub
            # past subscription, user is considered not having a subscription = free plan
            else:
                return None
        else:
            return sub 
开发者ID:simple-login,项目名称:app,代码行数:20,代码来源:models.py

示例8: greylisting_needed_for_alias

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def greylisting_needed_for_alias(alias: Alias) -> bool:
    min_time = arrow.now().shift(minutes=-1)

    # get the nb of activity on this alias
    nb_activity = (
        db.session.query(EmailLog)
        .join(Contact, EmailLog.contact_id == Contact.id)
        .filter(Contact.alias_id == alias.id, EmailLog.created_at > min_time,)
        .group_by(EmailLog.id)
        .count()
    )

    if nb_activity > MAX_ACTIVITY_DURING_MINUTE_PER_ALIAS:
        LOG.d(
            "Too much forward on alias %s. Nb Activity %s", alias, nb_activity,
        )
        return True

    return False 
开发者ID:simple-login,项目名称:app,代码行数:21,代码来源:greylisting.py

示例9: greylisting_needed_for_mailbox

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def greylisting_needed_for_mailbox(alias: Alias) -> bool:
    min_time = arrow.now().shift(minutes=-1)

    # get nb of activity on this mailbox
    nb_activity = (
        db.session.query(EmailLog)
        .join(Contact, EmailLog.contact_id == Contact.id)
        .join(Alias, Contact.alias_id == Alias.id)
        .filter(Alias.mailbox_id == alias.mailbox_id, EmailLog.created_at > min_time,)
        .group_by(EmailLog.id)
        .count()
    )

    if nb_activity > MAX_ACTIVITY_DURING_MINUTE_PER_MAILBOX:
        LOG.d(
            "Too much forward on mailbox %s, alias %s. Nb Activity %s",
            alias.mailbox,
            alias,
            nb_activity,
        )
        return True

    return False 
开发者ID:simple-login,项目名称:app,代码行数:25,代码来源:greylisting.py

示例10: current

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def current(self, value):
        if not value or 'project' not in value:
            self._current = {}

            if self._old_state is None:
                self._old_state = {}

            return

        start = value.get('start', arrow.now())

        if not isinstance(start, arrow.Arrow):
            start = self._parse_date(start)

        self._current = {
            'project': value['project'],
            'start': start,
            'tags': value.get('tags') or []
        }

        if self._old_state is None:
            self._old_state = self._current 
开发者ID:TailorDev,项目名称:Watson,代码行数:24,代码来源:watson.py

示例11: stop

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def stop(self, stop_at=None):
        if not self.is_started:
            raise WatsonError("No project started.")

        old = self.current

        if stop_at is None:
            # One cannot use `arrow.now()` as default argument. Default
            # arguments are evaluated when a function is defined, not when its
            # called. Since there might be huge delays between defining this
            # stop function and calling it, the value of `stop_at` could be
            # outdated if defined using a default argument.
            stop_at = arrow.now()
        if old['start'] > stop_at:
            raise WatsonError('Task cannot end before it starts.')
        if stop_at > arrow.now():
            raise WatsonError('Task cannot end in the future.')

        frame = self.frames.add(
            old['project'], old['start'], stop_at, tags=old['tags']
        )
        self.current = None

        return frame 
开发者ID:TailorDev,项目名称:Watson,代码行数:26,代码来源:watson.py

示例12: _parse_multiformat

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def _parse_multiformat(self, value):
        date = None
        for fmt in (None, 'HH:mm:ss', 'HH:mm'):
            try:
                if fmt is None:
                    date = arrow.get(value)
                else:
                    date = arrow.get(value, fmt)
                    date = arrow.now().replace(
                        hour=date.hour,
                        minute=date.minute,
                        second=date.second
                    )
                break
            except (ValueError, TypeError):
                pass
        return date 
开发者ID:TailorDev,项目名称:Watson,代码行数:19,代码来源:cli.py

示例13: test_start_project_at

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def test_start_project_at(watson):
    now = arrow.now()
    watson.start('foo', start_at=now)
    watson.stop()

    # Task can't start before the previous task ends
    with pytest.raises(WatsonError):
        time_str = '1970-01-01T00:00'
        time_obj = arrow.get(time_str)
        watson.start('foo', start_at=time_obj)

    # Task can't start in the future
    with pytest.raises(WatsonError):
        time_str = '2999-12-31T23:59'
        time_obj = arrow.get(time_str)
        watson.start('foo', start_at=time_obj)

    assert watson.frames[-1].start == now


# stop 
开发者ID:TailorDev,项目名称:Watson,代码行数:23,代码来源:test_watson.py

示例14: test_stop_started_project_at

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def test_stop_started_project_at(watson):
    watson.start('foo')
    now = arrow.now()

    # Task can't end before it starts
    with pytest.raises(WatsonError):
        time_str = '1970-01-01T00:00'
        time_obj = arrow.get(time_str)
        watson.stop(stop_at=time_obj)

    # Task can't end in the future
    with pytest.raises(WatsonError):
        time_str = '2999-12-31T23:59'
        time_obj = arrow.get(time_str)
        watson.stop(stop_at=time_obj)

    watson.stop(stop_at=now)
    assert watson.frames[-1].stop == now


# cancel 
开发者ID:TailorDev,项目名称:Watson,代码行数:23,代码来源:test_watson.py

示例15: parse_date

# 需要导入模块: import arrow [as 别名]
# 或者: from arrow import now [as 别名]
def parse_date(date):
    """
        Parses a date and returns it as YYYYMMDD
        If not parsable, returns False

        Args:
            date
    """
    try:
        parsed_date = parse(str(date))
    except ValueError:
        return False
    if (arrow.now().date() - parsed_date.date()).days < 0:
            raise ValueError("Date cannot be set in the future")
    return parsed_date.strftime("%Y%m%d")


#============#
# Validators #
#============# 
开发者ID:danielecook,项目名称:iex-api-python,代码行数:22,代码来源:utils.py


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