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


Python parser.isoparse方法代码示例

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


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

示例1: edit_reminder_content

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def edit_reminder_content(self, ctx: Context, id_: int, *, content: str) -> None:
        """Edit one of your reminder's content."""
        # Send the request to update the reminder in the database
        reminder = await self.bot.api_client.patch(
            'bot/reminders/' + str(id_),
            json={'content': content}
        )

        # Parse the reminder expiration back into a datetime for the confirmation message
        expiration = isoparse(reminder['expiration']).replace(tzinfo=None)

        # Send a confirmation message to the channel
        await self._send_confirmation(
            ctx,
            on_success="That reminder has been edited successfully!",
            reminder_id=id_,
            delivery_dt=expiration,
        )
        await self._reschedule_reminder(reminder) 
开发者ID:python-discord,项目名称:bot,代码行数:21,代码来源:reminders.py

示例2: _isoparse_date_and_time

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def _isoparse_date_and_time(dt, date_fmt, time_fmt, tzoffset,
                            microsecond_precision=None):
    tzi, offset_str = tzoffset
    fmt = date_fmt + 'T' + time_fmt
    dt = dt.replace(tzinfo=tzi)
    dtstr = dt.strftime(fmt)

    if microsecond_precision is not None:
        if not fmt.endswith('%f'):
            raise ValueError('Time format has no microseconds!')

        if microsecond_precision != 6:
            dtstr = dtstr[:-(6 - microsecond_precision)]
        elif microsecond_precision > 6:
            raise ValueError('Precision must be 1-6')

    dtstr += offset_str

    assert isoparse(dtstr) == dt 
开发者ID:MediaBrowser,项目名称:plugin.video.emby,代码行数:21,代码来源:test_isoparser.py

示例3: parse_articles

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def parse_articles(response):
    ''' Parses articles fetched from News API.

    Returns:
        A list of dicts containing publishing date, title, URL and source of
        articles.
    '''
    parsed_articles = []
    if response.get('status') == 'ok':
        for article in response.get('articles'):
            parsed_articles.append({
                'published_at':
                    parser.isoparse(article['publishedAt']
                                   ).strftime('%Y-%m-%d %H:%M'),
                'title':
                    article['title'],
                'url':
                    article['url'],
                'source':
                    article['source']['name']
            })
    return parsed_articles 
开发者ID:skamieniarz,项目名称:newspie,代码行数:24,代码来源:news.py

示例4: __init__

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def __init__(
            self,
            id=None,
            name=None,
            certificate=None,
            not_valid_before=None,
            not_valid_after=None,
            domain_names=None,
            fingerprint=None,
            created=None,
            labels=None,
    ):
        self.id = id
        self.name = name
        self.certificate = certificate
        self.domain_names = domain_names
        self.fingerprint = fingerprint
        self.not_valid_before = isoparse(not_valid_before) if not_valid_before else None
        self.not_valid_after = isoparse(not_valid_after) if not_valid_after else None
        self.created = isoparse(created) if created else None
        self.labels = labels 
开发者ID:hetznercloud,项目名称:hcloud-python,代码行数:23,代码来源:domain.py

示例5: __init__

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def __init__(
            self,
            id,
            name=None,
            created=None,
            ip_range=None,
            subnets=None,
            routes=None,
            servers=None,
            protection=None,
            labels=None,
    ):
        self.id = id
        self.name = name
        self.created = isoparse(created) if created else None
        self.ip_range = ip_range
        self.subnets = subnets
        self.routes = routes
        self.servers = servers
        self.protection = protection
        self.labels = labels 
开发者ID:hetznercloud,项目名称:hcloud-python,代码行数:23,代码来源:domain.py

示例6: check_underlier_fields

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def check_underlier_fields(
            underlier: Union[EqOption, EqVarianceSwap]
    ) -> Union[EqOption, EqVarianceSwap]:
        # validation for different fields
        if isinstance(underlier.expiration_date, datetime.date):
            underlier = underlier.clone()
            underlier.expiration_date = '{}d'.format(
                (underlier.expiration_date - PricingContext.current.pricing_date).days)
        elif re.search(ISO_FORMAT, underlier.expiration_date) is not None:
            underlier = underlier.clone()
            underlier.expiration_date = '{}d'.format(
                (isoparse(underlier.expiration_date).date() - PricingContext.current.pricing_date).days)

        if isinstance(underlier, EqOption):
            underlier.number_of_options = None

        return underlier 
开发者ID:goldmansachs,项目名称:gs-quant,代码行数:19,代码来源:strategy_systematic.py

示例7: set_stored_data_version

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def set_stored_data_version(
    workflow: Workflow, wf_module: WfModule, version: str, **kwargs
):
    try:
        # cast to str: dateutil.parser may have vulnerability with non-str
        version = str(version)
        version = isoparse(version)
    except (ValueError, OverflowError, TypeError):
        raise HandlerError("BadRequest: version must be an ISO8601 datetime")

    version = await _find_precise_version(wf_module, version)

    await commands.do(
        ChangeDataVersionCommand,
        workflow_id=workflow.id,
        wf_module=wf_module,
        new_version=version,
    )

    await _mark_stored_object_read(wf_module, version) 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:22,代码来源:wf_module.py

示例8: test_set_stored_data_version

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def test_set_stored_data_version(self):
        version = "2018-12-12T21:30:00.000Z"
        user = User.objects.create(username="a", email="a@example.org")
        workflow = Workflow.create_and_init(owner=user)
        wf_module = workflow.tabs.first().wf_modules.create(order=0, slug="step-1")
        wf_module.stored_objects.create(stored_at=isoparse(version), size=0)

        response = self.run_handler(
            set_stored_data_version,
            user=user,
            workflow=workflow,
            wfModuleId=wf_module.id,
            version=version,
        )
        self.assertResponse(response, data=None)
        wf_module.refresh_from_db()
        self.assertEqual(wf_module.stored_data_version, isoparse(version)) 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:19,代码来源:test_wf_module.py

示例9: test_set_stored_data_version_command_set_read

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def test_set_stored_data_version_command_set_read(self):
        version = "2018-12-12T21:30:00.000Z"
        user = User.objects.create(username="a", email="a@example.org")
        workflow = Workflow.create_and_init(owner=user)
        wf_module = workflow.tabs.first().wf_modules.create(order=0, slug="step-1")
        so = wf_module.stored_objects.create(
            stored_at=isoparse(version), size=0, read=False
        )

        response = self.run_handler(
            set_stored_data_version,
            user=user,
            workflow=workflow,
            wfModuleId=wf_module.id,
            version=version,
        )
        self.assertResponse(response, data=None)
        so.refresh_from_db()
        self.assertEqual(so.read, True) 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:21,代码来源:test_wf_module.py

示例10: test_set_stored_data_version_microsecond_date

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def test_set_stored_data_version_microsecond_date(self):
        version_precise = "2018-12-12T21:30:00.000123Z"
        version_js = "2018-12-12T21:30:00.000Z"
        user = User.objects.create(username="a", email="a@example.org")
        workflow = Workflow.create_and_init(owner=user)
        wf_module = workflow.tabs.first().wf_modules.create(order=0, slug="step-1")
        # Postgres will store this with microsecond precision
        wf_module.stored_objects.create(stored_at=isoparse(version_precise), size=0)

        # JS may request it with millisecond precision
        response = self.run_handler(
            set_stored_data_version,
            user=user,
            workflow=workflow,
            wfModuleId=wf_module.id,
            version=version_js,
        )
        self.assertResponse(response, data=None)
        wf_module.refresh_from_db()
        self.assertEqual(wf_module.stored_data_version, isoparse(version_precise)) 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:22,代码来源:test_wf_module.py

示例11: report_license_expiration

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def report_license_expiration(self):
        service_check_name = "{}.license_ok".format(self.NAMESPACE)
        try:
            license = self._retrieve_json("/api/v1/settings/license")
            if "expiration_date" not in license:
                raise Exception("expiration_date not found.")
        except Exception as e:
            self.warning("cannot retrieve license data: %s", e)
            self.service_check(service_check_name, AgentCheck.CRITICAL, tags=self.config.tags)
            raise e

        # alert if your license will expire in 30 days and then in a week
        expiration_date = parser.isoparse(license.get("expiration_date"))
        current_date = datetime.now(tz.tzutc())
        warning_date = current_date + timedelta(days=30)
        critical_date = current_date + timedelta(days=7)

        licence_status = AgentCheck.OK
        if expiration_date < warning_date:
            licence_status = AgentCheck.WARNING
        if expiration_date < critical_date:
            licence_status = AgentCheck.CRITICAL
        self.service_check(
            service_check_name, licence_status, tags=self.config.tags, message=license.get("expiration_date")
        ) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:27,代码来源:twistlock.py

示例12: reschedule_reminders

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def reschedule_reminders(self) -> None:
        """Get all current reminders from the API and reschedule them."""
        await self.bot.wait_until_guild_available()
        response = await self.bot.api_client.get(
            'bot/reminders',
            params={'active': 'true'}
        )

        now = datetime.utcnow()

        for reminder in response:
            is_valid, *_ = self.ensure_valid_reminder(reminder, cancel_task=False)
            if not is_valid:
                continue

            remind_at = isoparse(reminder['expiration']).replace(tzinfo=None)

            # If the reminder is already overdue ...
            if remind_at < now:
                late = relativedelta(now, remind_at)
                await self.send_reminder(reminder, late)
            else:
                self.schedule_task(reminder["id"], reminder) 
开发者ID:python-discord,项目名称:bot,代码行数:25,代码来源:reminders.py

示例13: _scheduled_task

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def _scheduled_task(self, reminder: dict) -> None:
        """A coroutine which sends the reminder once the time is reached, and cancels the running task."""
        reminder_id = reminder["id"]
        reminder_datetime = isoparse(reminder['expiration']).replace(tzinfo=None)

        # Send the reminder message once the desired duration has passed
        await wait_until(reminder_datetime)
        await self.send_reminder(reminder)

        log.debug(f"Deleting reminder {reminder_id} (the user has been reminded).")
        await self._delete_reminder(reminder_id) 
开发者ID:python-discord,项目名称:bot,代码行数:13,代码来源:reminders.py

示例14: test_timespec_auto

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def test_timespec_auto(dt, sep):
    if dt.tzinfo is not None:
        # Assume offset has no sub-second components
        assume(dt.utcoffset().total_seconds() % 60 == 0)

    sep = str(sep)          # Python 2.7 requires bytes
    dtstr = dt.isoformat(sep=sep)
    dt_rt = isoparse(dtstr)

    assert dt_rt == dt 
开发者ID:MediaBrowser,项目名称:plugin.video.emby,代码行数:12,代码来源:test_isoparse_prop.py

示例15: test_year_only

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import isoparse [as 别名]
def test_year_only(dt):
    dtstr = dt.strftime('%Y')

    assert isoparse(dtstr) == dt 
开发者ID:MediaBrowser,项目名称:plugin.video.emby,代码行数:6,代码来源:test_isoparser.py


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