Python isodate.parse_date() Examples
The following are 7
code examples of isodate.parse_date().
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: scrape.py From scrape-schema-recipe with Apache License 2.0 | 6 votes |
def _parse_determine_date_datetime(s: str) -> Union[datetime.datetime, datetime.date]: """Parse function parses a date, if time is included it parses as a datetime. """ if sys.version_info >= (3, 7): # Check if the date includes time. if 'T' in s: return datetime.datetime.fromisoformat(s) else: return datetime.date.fromisoformat(s) else: # Check if the date includes time. if 'T' in s: return isodate.parse_datetime(s) else: return isodate.parse_date(s) # Test if lists/tuples have contain matching items
Example #2
Source File: voat.py From CloudBot with GNU General Public License v3.0 | 6 votes |
def format_output(item, show_url=False): """ takes a voat post and returns a formatted string """ if not item["Title"]: item["Title"] = formatting.truncate(item["Linkdescription"], 70) else: item["Title"] = formatting.truncate(item["Title"], 70) item["link"] = voat_fill_url.format(item["Subverse"], item["Id"]) raw_time = isodate.parse_date(item['Date']) item["timesince"] = timeformat.time_since(raw_time, count=1, simple=True) item["comments"] = formatting.pluralize(item["CommentCount"], 'comment') item["points"] = formatting.pluralize(item["Likes"], 'point') if item["Type"] == 2: item["warning"] = " \x02Link\x02" else: item["warning"] = "" if show_url: return "\x02{Title} : {Subverse}\x02 - {comments}, {points}" \ " - \x02{Name}\x02 {timesince} ago - {link}{warning}".format(**item) else: return "\x02{Title} : {Subverse}\x02 - {comments}, {points}" \ " - \x02{Name}\x02, {timesince} ago{warning}".format(**item)
Example #3
Source File: test_date.py From autorest.python with MIT License | 6 votes |
def test_date(self): client = AutoRestDateTestService(base_url="http://localhost:3000") max_date = isodate.parse_date("9999-12-31T23:59:59.999999Z") min_date = isodate.parse_date("0001-01-01T00:00:00Z") await client.date_model.put_max_date(max_date) await client.date_model.put_min_date(min_date) assert max_date == await client.date_model.get_max_date() assert min_date == await client.date_model.get_min_date() assert await client.date_model.get_null() is None with pytest.raises(DeserializationError): await client.date_model.get_invalid_date() with pytest.raises(DeserializationError): await client.date_model.get_overflow_date() with pytest.raises(DeserializationError): await client.date_model.get_underflow_date()
Example #4
Source File: test_date.py From autorest.python with MIT License | 6 votes |
def test_date(self): client = AutoRestDateTestService(base_url="http://localhost:3000") max_date = isodate.parse_date("9999-12-31T23:59:59.999999Z") min_date = isodate.parse_date("0001-01-01T00:00:00Z") client.date_model.put_max_date(max_date) client.date_model.put_min_date(min_date) assert max_date == client.date_model.get_max_date() assert min_date == client.date_model.get_min_date() assert client.date_model.get_null() is None with pytest.raises(DeserializationError): client.date_model.get_invalid_date() with pytest.raises(DeserializationError): client.date_model.get_overflow_date() with pytest.raises(DeserializationError): client.date_model.get_underflow_date()
Example #5
Source File: serialization.py From msrest-for-python with MIT License | 5 votes |
def serialize_date(attr, **kwargs): """Serialize Date object into ISO-8601 formatted string. :param Date attr: Object to be serialized. :rtype: str """ if isinstance(attr, str): attr = isodate.parse_date(attr) t = "{:04}-{:02}-{:02}".format(attr.year, attr.month, attr.day) return t
Example #6
Source File: serialization.py From msrest-for-python with MIT License | 5 votes |
def deserialize_date(attr): """Deserialize ISO-8601 formatted string into Date object. :param str attr: response string to be deserialized. :rtype: Date :raises: DeserializationError if string format invalid. """ if isinstance(attr, ET.Element): attr = attr.text if re.search(r"[^\W\d_]", attr, re.I + re.U): raise DeserializationError("Date must have only digits and -. Received: %s" % attr) # This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception. return isodate.parse_date(attr, defaultmonth=None, defaultday=None)
Example #7
Source File: bandcamp.py From beets-bandcamp with GNU General Public License v2.0 | 5 votes |
def get_album_info(self, url): """Returns an AlbumInfo object for a bandcamp album page. """ try: html = self._get(url) name_section = html.find(id='name-section') album = name_section.find(attrs={'itemprop': 'name'}).text.strip() # Even though there is an item_id in some urls in bandcamp, it's not # visible on the page and you can't search by the id, so we need to use # the url as id. album_id = url artist = name_section.find(attrs={'itemprop': 'byArtist'}) .text.strip() release = html.find('meta', attrs={'itemprop': 'datePublished'})['content'] release = isodate.parse_date(release) artist_url = url.split('/album/')[0] tracks = [] for row in html.find(id='track_table').find_all(attrs={'itemprop': 'tracks'}): track = self._parse_album_track(row) track.track_id = '{0}{1}'.format(artist_url, track.track_id) tracks.append(track) return AlbumInfo(album, album_id, artist, artist_url, tracks, year=release.year, month=release.month, day=release.day, country='XW', media='Digital Media', data_source='bandcamp', data_url=url) except requests.exceptions.RequestException as e: self._log.debug("Communication error while fetching album {0!r}: " "{1}".format(url, e)) except (TypeError, AttributeError) as e: self._log.debug("Unexpected html while scraping album {0!r}: {1}".format(url, e)) except BandcampException as e: self._log.debug('Error: {0}'.format(e))