tomasbedrich / pycaching

A Python 3 interface for working with Geocaching.com website.
https://pycaching.readthedocs.io/
GNU Lesser General Public License v3.0
61 stars 46 forks source link

pycaching.cache.Cache._from_print_page not working with non-English languages #210

Open Jakoma02 opened 1 year ago

Jakoma02 commented 1 year ago

If the language of the webpage for the geocaching.com account is set to a different language than English, at least some parts of this package do not function correctly. For example, when the language is switched to Czech, the geocaching.my_logs(pycaching.log.Type.found_it, limit) method call raises the exception

    cache_info["summary"] = content.find("h2", text="Short Description").find_next("div").text
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'find_next'

The underlying issue seem to be that the info is parsed from the cache print page, which is retrieved in the language that the webpage UI is set to. For example, in the case of "Short Description" there is the title "Stručný popis" in the czech version instead.

FriedrichFroebel commented 1 year ago

Thanks for the report. It is a known limitation that only the English page is supported correctly. There have been some attempts to rely on "neutral" CSS classes and similar whenever parsing HTML, but this is not complete. AFAIK there does not seem to be a suitable language-independent solution for retrieving the descriptions from the print page.

Feel free to submit a PR fixing this issue if you have found a suitable solution which reliably removes the language-dependency in this case.