Python datetime.date.fromisoformat() Examples
The following are 12
code examples of datetime.date.fromisoformat().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
datetime.date
, or try the search function
.
Example #1
Source File: database.py From lbry-sdk with MIT License | 6 votes |
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 )
Example #2
Source File: datepicker.py From ultimate-poll-bot with MIT License | 6 votes |
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)
Example #3
Source File: datepicker.py From ultimate-poll-bot with MIT License | 6 votes |
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)
Example #4
Source File: datepicker.py From ultimate-poll-bot with MIT License | 6 votes |
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), )
Example #5
Source File: band_lpv2.py From huawei-lpv2 with MIT License | 5 votes |
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()
Example #6
Source File: generate_data.py From awesome-italy-events with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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())
Example #7
Source File: wikidata_bot.py From soweego with GNU General Public License v3.0 | 5 votes |
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
Example #8
Source File: bnb.py From airbnb-scraper with GNU General Public License v3.0 | 5 votes |
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
Example #9
Source File: datepicker.py From ultimate-poll-bot with MIT License | 5 votes |
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() )
Example #10
Source File: datepicker.py From ultimate-poll-bot with MIT License | 5 votes |
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() )
Example #11
Source File: option.py From ultimate-poll-bot with MIT License | 5 votes |
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
Example #12
Source File: option.py From ultimate-poll-bot with MIT License | 5 votes |
def as_date(self): """Either return the option as date or None.""" if not self.is_date: return None return date.fromisoformat(self.name)