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


Python date.fromisoformat方法代码示例

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


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

示例1: write_ical

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def write_ical(events, year, dataDir):
    # write iCal
    cal = Calendar()

    for awesomeEvent in events:
        event = Event()

        event.add('summary', awesomeEvent.title)
        event.add('dtstart', date.fromisoformat(awesomeEvent.startDate))
        event.add('dtend', date.fromisoformat(
            awesomeEvent.endDate) + timedelta(days=1))
        event.add('description',
                  f'{awesomeEvent.description} - {awesomeEvent.url}')
        event.add('location', awesomeEvent.location)
        cal.add_component(event)

    with open(f'{dataDir}{year}.ics', 'wb') as ics:
        ics.write(cal.to_ical()) 
开发者ID:ildoc,项目名称:awesome-italy-events,代码行数:20,代码来源:generate_data.py

示例2: get_txo_plot

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def get_txo_plot(self, start_day=None, days_back=0, end_day=None, days_after=None, **constraints):
        self._clean_txo_constraints_for_aggregation(constraints)
        if start_day is None:
            constraints['day__gte'] = self.ledger.headers.estimated_julian_day(
                self.ledger.headers.height
            ) - days_back
        else:
            constraints['day__gte'] = date_to_julian_day(
                date.fromisoformat(start_day)
            )
            if end_day is not None:
                constraints['day__lte'] = date_to_julian_day(
                    date.fromisoformat(end_day)
                )
            elif days_after is not None:
                constraints['day__lte'] = constraints['day__gte'] + days_after
        return await self.select_txos(
            "DATE(day) AS day, SUM(amount) AS total",
            group_by='day', order_by='day', **constraints
        ) 
开发者ID:lbryio,项目名称:lbry-sdk,代码行数:22,代码来源:database.py

示例3: owner_pick_date_option

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def owner_pick_date_option(session, context, poll, datepicker_context):
    """Owner adds or removes a date option."""
    picked_date = date.fromisoformat(context.data[2])

    # Check if we already have this date as option
    existing_option = poll.get_date_option(picked_date)
    # If that's the case, delete it
    if existing_option is not None:
        session.delete(existing_option)
        session.commit()
        message = i18n.t(
            "callback.date_removed", locale=poll.locale, date=picked_date.isoformat()
        )
    else:
        add_options_multiline(session, poll, context.data[2], is_date=True)
        message = i18n.t(
            "callback.date_picked", locale=poll.locale, date=picked_date.isoformat()
        )
    context.query.answer(message)

    update_datepicker(context, poll, datepicker_context, picked_date.replace(day=1))
    if poll.created:
        update_poll_messages(session, context.bot, poll) 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:25,代码来源:datepicker.py

示例4: pick_external_date

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def pick_external_date(session, context, poll):
    """Add or remove a date option during creation."""
    picked_date = date.fromisoformat(context.data[2])

    # Check if we already have this date as option
    existing_option = poll.get_date_option(picked_date)
    # If that's the case, delete it
    if existing_option is not None:
        return i18n.t("callback.date_already_picked", locale=poll.locale)

    add_options_multiline(session, poll, context.data[2], is_date=True)
    message = i18n.t(
        "callback.date_picked", locale=poll.locale, date=picked_date.isoformat()
    )
    context.query.answer(message)

    update_datepicker(
        context, poll, DatepickerContext.external_add_option, picked_date.replace(day=1)
    )
    update_poll_messages(session, context.bot, poll) 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:22,代码来源:datepicker.py

示例5: pick_due_date

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def pick_due_date(session, context, poll):
    """Set the due date for a poll."""
    picked_date = date.fromisoformat(context.data[2])
    if picked_date <= date.today():
        return i18n.t("callback.due_date_in_past", locale=poll.user.locale)

    due_date = datetime.combine(picked_date, time(hour=12, minute=00))
    if due_date == poll.due_date:
        poll.set_due_date(None)
        context.query.answer(
            i18n.t("callback.due_date_removed", locale=poll.user.locale)
        )
    else:
        poll.set_due_date(due_date)

    context.query.message.edit_text(
        text=get_settings_text(context.poll),
        parse_mode="markdown",
        reply_markup=get_due_date_datepicker_keyboard(poll, picked_date),
    ) 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:22,代码来源:datepicker.py

示例6: get_formatted_name

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def get_formatted_name(self):
        """Get the name depending on whether the option is a date."""
        if self.is_date and self.poll.european_date_format:
            option_date = date.fromisoformat(self.name)
            return option_date.strftime("%d.%m.%Y (%A)")
        elif self.is_date:
            option_date = date.fromisoformat(self.name)
            return option_date.strftime("%Y-%m-%d (%A)")

        return self.name 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:12,代码来源:option.py

示例7: run

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def run(config, loop):
    secret = base64.b64decode(config["secret"])
    device_uuid = config["device_uuid"]
    device_mac = config["device_mac"]
    client_mac = config["client_mac"]

    async with BleakClient(device_mac if platform.system() != "Darwin" else device_uuid, loop=loop) as client:
        band = Band(loop=loop, client=client, client_mac=client_mac, device_mac=device_mac, key=secret)

        await band.connect()
        await band.handshake()

        # await band.factory_reset()

        battery_level = await band.get_battery_level()
        logger.info(f"Battery level: {battery_level}")

        await band.set_right_wrist(False)
        await band.set_rotation_actions()
        await band.set_time()
        await band.set_locale("en-US", locale_config.MeasurementSystem.Metric)
        await band.set_date_format(device_config.DateFormat.YearFirst, device_config.TimeFormat.Hours24)

        await band.set_user_info(
            int(config.get("height", 170)), int(config.get("weight", 60)), fitness.Sex(int(config.get("sex", 1))),
            date.fromisoformat(config.get("birth_date", "1990-08-01")),
        )

        await band.enable_trusleep(True)
        await band.enable_heart_rate_monitoring(False)

        today_totals = await band.get_today_totals()
        logger.info(f"Today totals: {today_totals}")

        # await band.send_notification("Really nice to see you ^__^", "Hello, World!",
        #                              vibrate=True, notification_type=NotificationType.Email)

        await band.disconnect() 
开发者ID:zyv,项目名称:huawei-lpv2,代码行数:40,代码来源:band_lpv2.py

示例8: _parse_value

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def _parse_value(value):
    # It may not be a string
    if not isinstance(value, str):
        value = str(value)
    # Build an item in case of QID
    value_is_qid = search(QID_REGEX, value)
    if value_is_qid:
        return pywikibot.ItemPage(REPO, value_is_qid.group())
    # Try to build a date
    try:
        date_value = date.fromisoformat(value)
        # Precision hack: it's a year if both month and day are 1
        precision = (
            vocabulary.YEAR
            if date_value.month == 1 and date_value.day == 1
            else vocabulary.DAY
        )
        return pywikibot.WbTime(
            date_value.year,
            date_value.month,
            date_value.day,
            precision=precision,
        )
    # Otherwise return the value as is
    except ValueError:
        return value 
开发者ID:Wikidata,项目名称:soweego,代码行数:28,代码来源:wikidata_bot.py

示例9: _build_date_range

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def _build_date_range(iso_date: str, range_spec: str):
        """Calculate start and end dates for a range. Return start date and timedelta for number of days."""
        base_date = date.fromisoformat(iso_date)
        if range_spec.startswith('+-'):  # +-7
            days = float(re.match(r'\+\-(\d+)', range_spec).group(1))
            start_date = base_date - timedelta(days=days)
            end_date = base_date + timedelta(days=days)
        else:  # +0-3
            result = re.match(r'\+(\d+)\-(\d+)', range_spec)
            post_days = float(result.group(1))
            pre_days = float(result.group(2))
            start_date = base_date - timedelta(days=pre_days)
            end_date = base_date + timedelta(days=post_days)
        return start_date, end_date - start_date 
开发者ID:digital-engineering,项目名称:airbnb-scraper,代码行数:16,代码来源:bnb.py

示例10: set_next_month

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def set_next_month(session, context, poll):
    """Show the datepicker keyboard for the next month."""
    this_month = date.fromisoformat(context.data[2])
    datepicker_context = DatepickerContext(int(context.data[3]))

    next_month = this_month + relativedelta(months=1)
    update_datepicker(context, poll, datepicker_context, next_month)
    return i18n.t(
        "callback.date_changed", locale=poll.locale, date=next_month.isoformat()
    ) 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:12,代码来源:datepicker.py

示例11: set_previous_month

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def set_previous_month(session, context, poll):
    """Show the datepicker keyboard for the previous month."""
    this_month = date.fromisoformat(context.data[2])
    datepicker_context = DatepickerContext(int(context.data[3]))

    previous_month = this_month - relativedelta(months=1)
    update_datepicker(context, poll, datepicker_context, previous_month)
    return i18n.t(
        "callback.date_changed", locale=poll.locale, date=previous_month.isoformat()
    ) 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:12,代码来源:datepicker.py

示例12: as_date

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import fromisoformat [as 别名]
def as_date(self):
        """Either return the option as date or None."""
        if not self.is_date:
            return None
        return date.fromisoformat(self.name) 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:7,代码来源:option.py


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