Skip to content

Error raise while log a TB #130

@ghost

Description

Hi, as i use in my python file

trackable = geocaching.get_trackable(x)
print(trackable.name, trackable.goal, trackable.description, trackable.location)
log = Log(type=LogType.discovered_it, text=logtext, visited=datetime.date.today())
tracking_code = x
trackable.post_log(log, tracking_code)

it raises an error like:

Traceback (most recent call last):
  File ".../main.py", line 95, in <module>
    main()
  File ".../main.py", line 86, in main
    trackable.post_log(log, tracking_code)
  File "...\venv\lib\site-packages\pycaching\trackable.py", line 242, in post_log
    formatted_date = format_date(log.visited, date_format)
  File ...\venv\lib\site-packages\pycaching\util.py", line 91, in format_date
    return date.strftime(date_format)
ValueError: Invalid format string

Tested under:
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)]

i make a change to get it work in util.py i do:

def format_date(date, user_date_format):
    """Format a date according to user_date_format."""
    # parse user format
    date_format = user_date_format.lower()
    date_format = re.split("(\W+)", date_format)
    formats = {
        "dd": r'%d',
        "d": r'%-d',
        "mmm": r'%b',
        "mm": r'%m',
        "m": r'%-m',
        "yyyy": r'%Y',
        "yy": r'%y',
    }
    date_format = "".join((formats[c] if c in formats else c for c in date_format))
    if not type(date_format) == str:
        return date.strftime(date_format)
    else:
        return date_format

that works for me.
please excuse the long post, i am not familiar with this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions