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


Python isodate.parse_date方法代码示例

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


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

示例1: _parse_determine_date_datetime

# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import parse_date [as 别名]
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 
开发者ID:micahcochran,项目名称:scrape-schema-recipe,代码行数:22,代码来源:scrape.py

示例2: format_output

# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import parse_date [as 别名]
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) 
开发者ID:CloudBotIRC,项目名称:CloudBot,代码行数:27,代码来源:voat.py

示例3: test_date

# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import parse_date [as 别名]
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() 
开发者ID:Azure,项目名称:autorest.python,代码行数:22,代码来源:test_date.py

示例4: test_date

# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import parse_date [as 别名]
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() 
开发者ID:Azure,项目名称:autorest.python,代码行数:22,代码来源:test_date.py

示例5: serialize_date

# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import parse_date [as 别名]
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 
开发者ID:Azure,项目名称:msrest-for-python,代码行数:12,代码来源:serialization.py

示例6: deserialize_date

# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import parse_date [as 别名]
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) 
开发者ID:Azure,项目名称:msrest-for-python,代码行数:15,代码来源:serialization.py

示例7: get_album_info

# 需要导入模块: import isodate [as 别名]
# 或者: from isodate import parse_date [as 别名]
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)) 
开发者ID:unrblt,项目名称:beets-bandcamp,代码行数:34,代码来源:bandcamp.py


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