Python isodate.ISO8601Error() Examples
The following are 4
code examples of isodate.ISO8601Error().
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
isodate
, or try the search function
.
Example #1
Source File: metadata.py From C-3PO with MIT License | 6 votes |
def _insert_post(url, user, data, session): try: date_time = parse_datetime(data["created_time"]) except ISO8601Error: date_time = datetime.now() if not data.get("message") or len(data.get("message")) > 160: caption = "" else: caption = data.get("message").strip() facebook_id = data["id"] likes_count = data["reactions"]["summary"]["total_count"] permalink_url = data["permalink_url"] new_link = _insert_link(url, session) if not new_link: new_link = session.query(Link).filter(Link.url == url).first() new_post = UserPosts( user, new_link, date_time, caption, facebook_id, permalink_url ) new_post.likes_count = likes_count session.add(new_post) return None new_post = UserPosts(user, new_link, date_time, caption, facebook_id, permalink_url) new_post.likes_count = likes_count session.add(new_post) return new_link
Example #2
Source File: scrape.py From scrape-schema-recipe with Apache License 2.0 | 5 votes |
def _convert_properties_scrape(recipes: List[Dict], properties: frozenset, function: Callable[[str], Union[datetime.datetime, datetime.date]]) -> List[Dict]: for i in range(len(recipes)): key_set = set(recipes[i].keys()) for p in key_set.intersection(properties): try: recipes[i][p] = function(recipes[i][p]) except (isodate.ISO8601Error, ValueError): # parse error, just leave the value as is pass return recipes
Example #3
Source File: config.py From modmail with GNU Affero General Public License v3.0 | 4 votes |
def get(self, key: str, convert=True) -> typing.Any: value = self.__getitem__(key) if not convert: return value if key in self.colors: try: return int(value.lstrip("#"), base=16) except ValueError: logger.error("Invalid %s provided.", key) value = int(self.remove(key).lstrip("#"), base=16) elif key in self.time_deltas: if not isinstance(value, isodate.Duration): try: value = isodate.parse_duration(value) except isodate.ISO8601Error: logger.warning( "The {account} age limit needs to be a " 'ISO-8601 duration formatted duration, not "%s".', value, ) value = self.remove(key) elif key in self.booleans: try: value = strtobool(value) except ValueError: value = self.remove(key) elif key in self.special_types: if value is None: return None if key == "status": try: # noinspection PyArgumentList value = discord.Status(value) except ValueError: logger.warning("Invalid status %s.", value) value = self.remove(key) elif key == "activity_type": try: # noinspection PyArgumentList value = discord.ActivityType(value) except ValueError: logger.warning("Invalid activity %s.", value) value = self.remove(key) return value
Example #4
Source File: config.py From modmail with GNU Affero General Public License v3.0 | 4 votes |
def set(self, key: str, item: typing.Any, convert=True) -> None: if not convert: return self.__setitem__(key, item) if key in self.colors: try: hex_ = str(item) if hex_.startswith("#"): hex_ = hex_[1:] if len(hex_) == 3: hex_ = "".join(s for s in hex_ for _ in range(2)) if len(hex_) != 6: raise InvalidConfigError("Invalid color name or hex.") try: int(hex_, 16) except ValueError: raise InvalidConfigError("Invalid color name or hex.") except InvalidConfigError: name = str(item).lower() name = re.sub(r"[\-+|. ]+", " ", name) hex_ = ALL_COLORS.get(name) if hex_ is None: name = re.sub(r"[\-+|. ]+", "", name) hex_ = ALL_COLORS.get(name) if hex_ is None: raise return self.__setitem__(key, "#" + hex_) if key in self.time_deltas: try: isodate.parse_duration(item) except isodate.ISO8601Error: try: converter = UserFriendlyTimeSync() time = converter.convert(None, item) if time.arg: raise ValueError except BadArgument as exc: raise InvalidConfigError(*exc.args) except Exception as e: logger.debug(e) raise InvalidConfigError( "Unrecognized time, please use ISO-8601 duration format " 'string or a simpler "human readable" time.' ) item = isodate.duration_isoformat(time.dt - converter.now) return self.__setitem__(key, item) if key in self.booleans: try: return self.__setitem__(key, strtobool(item)) except ValueError: raise InvalidConfigError("Must be a yes/no value.") # elif key in self.special_types: # if key == "status": return self.__setitem__(key, item)