Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _parse_interval(value):
"""Do some nasty try/except voodoo to get some sort of datetime
object(s) out of the string.
"""
try:
return sorted(aniso8601.parse_interval(value))
except ValueError:
try:
return aniso8601.parse_datetime(value), None
except ValueError:
return aniso8601.parse_date(value), None
def converter(self, value):
return aniso8601.parse_date(value)
def dialog_tide(city, date):
if city is not None:
if city.lower() not in STATIONS:
return supported_cities()
if SESSION_DATE not in session.attributes:
session.attributes[SESSION_CITY] = city
return _dialog_date(city)
date = aniso8601.parse_date(session.attributes[SESSION_DATE])
return _make_tide_request(city, date)
elif date is not None:
if SESSION_CITY not in session.attributes:
session.attributes[SESSION_DATE] = date.isoformat()
return _dialog_city(date)
city = session.attributes[SESSION_CITY]
return _make_tide_request(city, date)
else:
return _dialog_no_slot()
def _parse_interval(value):
"""Do some nasty try/except voodoo to get some sort of datetime
object(s) out of the string.
"""
try:
return sorted(aniso8601.parse_interval(value))
except ValueError:
try:
return aniso8601.parse_datetime(value), None
except ValueError:
return aniso8601.parse_date(value), None
"int": fields.Integer,
"float": fields.Float,
"bool": fields.Boolean,
"datetime": fields.DateTime,
"date": fields.Date,
}
model_dict: Dict = {}
model_sample: Dict = trained_model_wrapper.sample()
if model_sample:
for key, value in model_sample.items():
fields_class: fields.Raw = fields_classes_map.get(
type(value).__name__, fields.String
)
if type(value).__name__ == "str":
try:
parse_date(value)
fields_class = fields.Date
except ValueError:
pass
try:
parse_datetime(value)
fields_class = fields.DateTime
except ValueError:
pass
model_dict[key] = fields_class(example=value, readonly=True, required=True)
return api.model("input_vector", model_dict)
def _parse_interval(value):
"""Do some nasty try/except voodoo to get some sort of datetime
object(s) out of the string.
"""
try:
return sorted(aniso8601.parse_interval(value))
except ValueError:
try:
return aniso8601.parse_datetime(value), None
except ValueError:
return aniso8601.parse_date(value), None
def _parse_interval(value):
'''
Do some nasty try/except voodoo to get some sort of datetime
object(s) out of the string.
'''
try:
return sorted(aniso8601.parse_interval(value))
except ValueError:
try:
return aniso8601.parse_datetime(value), None
except ValueError:
return aniso8601.parse_date(value), None
Example::
inputs.datetime_from_iso8601("2012-01-01T23:30:00+02:00")
:param str value: The ISO8601-complying string to transform
:return: A datetime
:rtype: datetime
:raises ValueError: if value is an invalid date literal
'''
try:
try:
return aniso8601.parse_datetime(value)
except ValueError:
date = aniso8601.parse_date(value)
return datetime(date.year, date.month, date.day)
except Exception:
raise ValueError('Invalid date literal "{0}"'.format(value))
def parse_value(value):
try:
if isinstance(value, datetime.date):
return value
elif isinstance(value, string_types):
return parse_date(value)
except ValueError:
return None