コード例 #1
0
ファイル: matching.py プロジェクト: david-caro/inspire-next
def is_too_old(record, days_ago=5):
    """Return True if the record is more than days_ago days old.

    If the record is older then it's probably an update of an earlier
    record, and we don't want those.
    """
    date_format = "%Y-%m-%d"
    earliest_date = record.get('earliest_date', '')
    if not earliest_date:
        earliest_date = record.get('preprint_date', '')

    if earliest_date:
        try:
            parsed_date = datetime.datetime.strptime(
                earliest_date,
                date_format,
            )

        except ValueError as err:
            raise ValueError(
                (
                    'Unrecognized earliest_date format "%s", valid formats is '
                    '%s: %s'
                ) % (earliest_date, date_format, err)
            )

        if not date_older_than(
            parsed_date,
            datetime.datetime.utcnow(),
            days=days_ago,
        ):
            return False
    return True
コード例 #2
0
def is_too_old(record, days_ago=5):
    """Return True if the record is more than days_ago days old.

    If the record is older then it's probably an update of an earlier
    record, and we don't want those.
    """
    date_format = "%Y-%m-%d"
    earliest_date = record.get('earliest_date', '')
    if not earliest_date:
        earliest_date = record.get('preprint_date', '')

    if earliest_date:
        try:
            parsed_date = datetime.datetime.strptime(
                earliest_date,
                date_format,
            )

        except ValueError as err:
            raise ValueError(
                ('Unrecognized earliest_date format "%s", valid formats is '
                 '%s: %s') % (earliest_date, date_format, err))

        if not date_older_than(
                parsed_date,
                datetime.datetime.utcnow(),
                days=days_ago,
        ):
            return False
    return True
コード例 #3
0
def is_too_old(record, days_ago=5):
    """Return True if the record is more than days_ago days old.

    If the record is older then it's probably an update of an earlier
    record, and we don't want those.
    """
    earliest_date = record.get("earliest_date", "")
    if not earliest_date:
        earliest_date = record.get("preprint_date", "")
    parsed_date = datetime.datetime.strptime(earliest_date, "%Y-%m-%d")
    if date_older_than(parsed_date, datetime.datetime.now(), days=days_ago):
        return True
コード例 #4
0
def is_too_old(record, days_ago=5):
    """Return True if the record is more than days_ago days old.

    If the record is older then it's probably an update of an earlier
    record, and we don't want those.
    """
    earliest_date = record.get('earliest_date', '')
    if not earliest_date:
        earliest_date = record.get('preprint_date', '')
    if earliest_date:
        parsed_date = datetime.datetime.strptime(earliest_date, "%Y-%m-%d")
        if not date_older_than(
                parsed_date, datetime.datetime.now(), days=days_ago):
            return False
    return True
コード例 #5
0
def test_newer_date():
    """date_older_than recognizes newer dates."""
    some_date = datetime.strptime("2015-01-01", "%Y-%m-%d")
    three_days_later = datetime.strptime("2015-01-04", "%Y-%m-%d")

    assert not date_older_than(some_date, three_days_later, days=6)
コード例 #6
0
def test_newer_date():
    """date_older_than recognizes newer dates."""
    some_date = datetime.strptime("2015-01-01", "%Y-%m-%d")
    three_days_later = datetime.strptime("2015-01-04", "%Y-%m-%d")

    assert not date_older_than(some_date, three_days_later, days=6)