Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date in unexpected format in one of the latest "updates" articles #45

Closed
coffeeinmypaintwater opened this issue Jun 22, 2024 · 2 comments
Assignees
Labels

Comments

@coffeeinmypaintwater
Copy link

Parsing updates █████████░ 570/577 00:00:00 Updates/13.36.5b5f56
Traceback (most recent call last):
File "/home/user/miniconda/envs/tibia/lib/python3.11/site-packages/tibiawikisql/utils.py", line 204, in parse_date
dt = datetime.datetime.strptime(value, "%B %d, %Y")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/miniconda/envs/tibia/lib/python3.11/_strptime.py", line 567, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/miniconda/envs/tibia/lib/python3.11/_strptime.py", line 352, in _strptime
raise ValueError("unconverted data remains: %s" %
ValueError: unconverted data remains: 17:45

File "/home/victor/miniconda/envs/tibia/lib/python3.11/_strptime.py", line 567, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/victor/miniconda/envs/tibia/lib/python3.11/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data 'May 14, 2024 17:45' does not match format '%Y'

@coffeeinmypaintwater
Copy link
Author

coffeeinmypaintwater commented Jun 22, 2024

I added possible date formats to the utils.py/parse_date as follows to get around the issue. Reinstalled and got past the error.

def parse_date(value):
    """Parse a date from the formats used in TibiaWiki.

    - June 28, 2019
    - Aug 21, 2014
    - May 14, 2024 17:45

    Parameters
    ----------
    value: :class:`str`
        The string containing the date.

    Returns
    -------
    :class:`str`
        The date represented by the string in ISO format.
    
    value = value.strip()
    date_formats = [
        "%B %d, %Y %H:%M",
        "%B %d, %Y",
        "%b %d, %Y %H:%M",
        "%b %d, %Y",
        "%Y %H:%M",
        "%Y"
    ]

    for date_format in date_formats:
        try:
            dt = datetime.datetime.strptime(value, date_format)
            return dt.date().isoformat()
        except ValueError:
            continue

    raise ValueError(f"Date format for value '{value}' not recognized")

@Galarzaa90 Galarzaa90 added the bug label Jun 27, 2024
@Galarzaa90 Galarzaa90 self-assigned this Jun 27, 2024
Galarzaa90 added a commit that referenced this issue Jun 27, 2024
@Galarzaa90
Copy link
Owner

Thank you! This is fixed in the v6.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants