Skip to content

Commit

Permalink
Merge pull request #181 from GTBoon72/issue_179
Browse files Browse the repository at this point in the history
Fix cache loading with the latest Geocaching.com site changes
  • Loading branch information
FriedrichFroebel authored Feb 23, 2022
2 parents af2f10d + 095fb5b commit cfac3fc
Show file tree
Hide file tree
Showing 41 changed files with 558 additions and 843 deletions.
5 changes: 3 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ If you haven't written or modified any tests, tests can be run just like:

.. code-block:: bash
pytest
pytest <test folder name>
If you have written or modified tests, you must provide a username and password for testing. Don't
worry, these will not leave your computer. Betamax will insert a placeholder when it records any
new cassettes. To run new tests, first set up the following environment variables:

.. code-block:: bash
PYCACHING_TEST_USERNAME="yourusername" PYCACHING_TEST_PASSWORD="yourpassword" pytest
PYCACHING_TEST_USERNAME="yourusername" PYCACHING_TEST_PASSWORD="yourpassword" pytest <test folder name>
Substitute your username for ``yourusername`` and your password for ``yourpassword``.
This requires you to use a basic member account, otherwise you might see unexpected test failures.

To re-record a specific cassette in case of site changes, delete the corresponding JSON file and
provide username and password as explained above. The missing cassette will be recorded for future
Expand Down
4 changes: 2 additions & 2 deletions pycaching/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def load(self):
self.wp = root.title.string.split(" ")[0]
except ValueError:
raise errors.LoadError()
self.name = cache_details.find("h2").text
self.name = cache_details.find(id="ctl00_ContentBody_CacheName").text

self.author = cache_details("a")[1].text

Expand Down Expand Up @@ -926,7 +926,7 @@ def _get_log_counts_from_cache_details(soup):
:param bs4.BeautifulSoup soup: Parsed html document of the cache details page.
"""
lbl_find_counts = soup.find("span", {"id": "ctl00_ContentBody_lblFindCounts"})
log_totals = lbl_find_counts.find("p", "LogTotals")
log_totals = lbl_find_counts.find("ul", "LogTotals")

# Text gives numbers separated by a lot of spaces, splitting retrieves the numbers.
# The values might contain thousand separators, which we have to remove before converting
Expand Down
34 changes: 11 additions & 23 deletions test/cassettes/cache_PMO.json

Large diffs are not rendered by default.

33 changes: 11 additions & 22 deletions test/cassettes/cache_explicit_load.json

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions test/cassettes/cache_guidload_PMO.json

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions test/cassettes/cache_guidload_fallback.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"http_interactions": [
{
"recorded_at": "2021-11-14T01:36:56",
"recorded_at": "2022-02-22T16:26:03",
"request": {
"body": {
"encoding": "utf-8",
Expand All @@ -21,7 +21,7 @@
"gspkauth=<AUTH COOKIE>; Culture=en-US; __RequestVerificationToken=<AUTH COOKIE>"
],
"User-Agent": [
"python-requests/2.26.0"
"python-requests/2.25.1"
]
},
"method": "GET",
Expand All @@ -30,7 +30,7 @@
"response": {
"body": {
"encoding": "utf-8",
"string": "\n\n<!DOCTYPE html>\n<html>\n<head>\n <title>DNF</title>\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <link href=\"//fonts.googleapis.com/css?family=Noto+Sans:400,700&subset=latin,latin-ext\" rel=\"stylesheet\" type=\"text/css\" />\n <link rel=\"stylesheet\" href=\"https://www.geocaching.com/app/ui-scss/layout.css\" />\n</head>\n\n\n<body>\n\n <div class=\"content-slide layout-callout\">\n <header>\n <div class=\"wrapper\">\n <a class=\"logo\" href=\"https://www.geocaching.com/\" title=\"Geocaching\" accesskey=\"0\">\n <svg viewBox=\"0 0 196 29\" role=\"img\"><title>Geocaching</title><path d=\"M113.5 6H111l-7.2 17.2h3.6l1.9-4.5h6.1l1.9 4.4h3.5L113.5 6zm-3 9.6l1.8-5.2 1.9 5.2h-3.7zM59.3 9v4h5.8v3.1h-5.8v4h6.1v3.1h-9.3V6h9.3v3.1L59.3 9zm65.7 1.4c-1.1 1.2-1.6 2.6-1.6 4.2 0 1.5.5 2.9 1.6 4.1 1.1 1.2 2.4 1.8 4.1 1.8.8 0 1.5-.1 2.2-.4.7-.3 1.3-.7 1.8-1.3l.3-.3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3.3 7.3H0V.1h13.4zM8.3 3.2c0-.6-.5-1.1-1.1-1.1-.7 0-1.2.5-1.2 1.1 0 .6.5 1.1 1.1 1.1.7 0 1.2-.5 1.2-1.1zM15.5.1v2.5c2.5.2 4.8 1.2 6.6 2.7l-1.6 1.6c-1.4-1.1-3.1-1.9-5-2v8.7h8.7c-.2-1.9-.9-3.6-2-5L23.7 7c1.5 1.8 2.5 4.1 2.7 6.6h2.5V.1H15.5zM6.9 23.8l1.6-1.6c1.4 1.1 3.1 1.8 5 2v-8.7H4.7c.2 1.9.9 3.6 2 5l-1.6 1.6c-1.5-1.8-2.5-4.1-2.7-6.6H0V29h13.4v-2.5c-2.4-.3-4.7-1.2-6.5-2.7z\" fill=\"#FFF\"/></svg>\n </a>\n </div>\n </header>\n\n <div class=\"main layout-callout\" id=\"Content\">\n <div class=\"wrapper\">\n <div class=\"callout http-error\">\n <h1 class=\"http-error-title\">Error 404: DNF</h1>\n <p>We didn't find the page you were looking for. Sorry about that! Visit the <a href=\"https://www.geocaching.com/help\">Help Center</a> or follow <a href=\"https://www.twitter.com/GoGeocaching\">Geocaching on Twitter</a> to see any available outage information.</p>\n <a href=\"https://www.geocaching.com/\" class=\"btn btn-primary\">Geocaching home</a>\n </div>\n </div>\n </div>\n\n <footer id=\"gcFooter\">\n <div class=\"copyright\">\n <div class=\"wrapper\">\n <p>&copy; 2000-2021 Groundspeak Inc. All Rights Reserved. <a href=\"https://www.geocaching.com/account/documents/termsofuse\">Groundspeak Terms of Use</a> | <a href=\"https://www.geocaching.com/account/documents/privacypolicy\">Privacy Policy</a></p>\n </div>\n </div>\n </footer>\n </div>\n</body>\n</html>\n"
"string": "\n\n<!DOCTYPE html>\n<html>\n<head>\n <title>DNF</title>\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <link href=\"//fonts.googleapis.com/css?family=Noto+Sans:400,700&subset=latin,latin-ext\" rel=\"stylesheet\" type=\"text/css\" />\n <link rel=\"stylesheet\" href=\"https://www.geocaching.com/app/ui-scss/layout.css\" />\n</head>\n\n\n<body>\n\n <div class=\"content-slide layout-callout\">\n <header>\n <div class=\"wrapper\">\n <a class=\"logo\" href=\"https://www.geocaching.com/\" title=\"Geocaching\" accesskey=\"0\">\n <svg viewBox=\"0 0 196 29\" role=\"img\"><title>Geocaching</title><path d=\"M113.5 6H111l-7.2 17.2h3.6l1.9-4.5h6.1l1.9 4.4h3.5L113.5 6zm-3 9.6l1.8-5.2 1.9 5.2h-3.7zM59.3 9v4h5.8v3.1h-5.8v4h6.1v3.1h-9.3V6h9.3v3.1L59.3 9zm65.7 1.4c-1.1 1.2-1.6 2.6-1.6 4.2 0 1.5.5 2.9 1.6 4.1 1.1 1.2 2.4 1.8 4.1 1.8.8 0 1.5-.1 2.2-.4.7-.3 1.3-.7 1.8-1.3l.3-.3h3.7l-.2.4c-.8 1.5-1.9 2.6-3.3 3.5-1.4.8-2.9 1.3-4.5 1.3-2.4 0-4.5-.9-6.3-2.6-1.7-1.7-2.6-3.9-2.6-6.5s.9-4.7 2.6-6.4c1.7-1.7 3.8-2.6 6.2-2.6 1.6 0 3.1.4 4.5 1.2 1.4.8 2.5 2 3.3 3.4l.3.6h-3.7l-.4-.4c-.5-.6-1.1-1-1.8-1.3-.7-.3-1.4-.4-2.2-.4-1.5 0-2.9.6-4 1.7zm-33.6 0c-1.1 1.2-1.6 2.6-1.6 4.2 0 1.5.5 2.9 1.6 4.1 1.1 1.2 2.4 1.8 4.1 1.8.8 0 1.5-.1 2.2-.4.7-.3 1.3-.7 1.8-1.3l.3-.3h3.7l-.2.4c-.8 1.5-1.9 2.6-3.3 3.5-1.4.9-2.9 1.3-4.5 1.3-2.4 0-4.5-.9-6.3-2.6-1.7-1.7-2.6-3.9-2.6-6.5s.9-4.7 2.6-6.4c1.7-1.7 3.8-2.6 6.2-2.6 1.6 0 3.1.4 4.5 1.2 1.4.8 2.5 2 3.3 3.4l.3.6h-3.7l-.4-.4c-.5-.6-1.1-1-1.8-1.3-.7-.3-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 0 .2-.1.3-.3.4l.3.4v.1h-.3l-.3-.4h-.1v.4h-.3V.6zm.3.3v.3h.3c.1 0 .2-.1.2-.2s-.1-.2-.2-.2h-.3zm-1.7 14.7V29H21l-1.6-6.3c.6-.8 1.3-1.1 2.8-1.3 2.9-.5 3.4-3 3.4-3-1.4.3-2.4 0-3.7-.3-1.3-.3-2.5-.3-3.6.1-.9.3-1.1.6-1.1.6L19.8 29h-4.3V15.6h13.4zM13.4.1v13.4H4.7c0-2.3.9-4.8 2.4-6.3 1.5 1.2 2.5 2.7 2.9 4.6h2.2c-.6-2.7-2.1-4.4-3.9-5.6C10.6 4.5 11 2.7 11 1.8h-.9c-.1.9-.6 2.2-3 3.6C4.6 4 4.2 2.7 4.2 1.8h-.9c0 1 .4 2.9 2.6 4.5-2.2 2.2-3.1 5-3.3 7.3H0V.1h13.4zM8.3 3.2c0-.6-.5-1.1-1.1-1.1-.7 0-1.2.5-1.2 1.1 0 .6.5 1.1 1.1 1.1.7 0 1.2-.5 1.2-1.1zM15.5.1v2.5c2.5.2 4.8 1.2 6.6 2.7l-1.6 1.6c-1.4-1.1-3.1-1.9-5-2v8.7h8.7c-.2-1.9-.9-3.6-2-5L23.7 7c1.5 1.8 2.5 4.1 2.7 6.6h2.5V.1H15.5zM6.9 23.8l1.6-1.6c1.4 1.1 3.1 1.8 5 2v-8.7H4.7c.2 1.9.9 3.6 2 5l-1.6 1.6c-1.5-1.8-2.5-4.1-2.7-6.6H0V29h13.4v-2.5c-2.4-.3-4.7-1.2-6.5-2.7z\" fill=\"#FFF\"/></svg>\n </a>\n </div>\n </header>\n\n <div class=\"main layout-callout\" id=\"Content\">\n <div class=\"wrapper\">\n <div class=\"callout http-error\">\n <h1 class=\"http-error-title\">Error 404: DNF</h1>\n <p>We didn't find the page you were looking for. Sorry about that! Visit the <a href=\"https://www.geocaching.com/help\">Help Center</a> or follow <a href=\"https://www.twitter.com/GoGeocaching\">Geocaching on Twitter</a> to see any available outage information.</p>\n <a href=\"https://www.geocaching.com/\" class=\"btn btn-primary\">Geocaching home</a>\n </div>\n </div>\n </div>\n\n <footer id=\"gcFooter\">\n <div class=\"copyright\">\n <div class=\"wrapper\">\n <p>&copy; 2000-2022 Groundspeak Inc. All Rights Reserved. <a href=\"https://www.geocaching.com/account/documents/termsofuse\">Groundspeak Terms of Use</a> | <a href=\"https://www.geocaching.com/account/documents/privacypolicy\">Privacy Policy</a></p>\n </div>\n </div>\n </footer>\n </div>\n</body>\n</html>\n"
},
"headers": {
"Cache-Control": [
Expand All @@ -43,20 +43,14 @@
"text/html; charset=utf-8"
],
"Date": [
"Sun, 14 Nov 2021 01:36:55 GMT"
"Tue, 22 Feb 2022 16:26:03 GMT"
],
"Request-Context": [
"appId=cid-v1:019d82c2-5dd7-44cb-aa94-01e052f0d40c"
],
"Server": [
"Microsoft-IIS/10.0"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-AspNet-Version": [
"4.0.30319"
],
"X-Content-Type-Options": [
"nosniff"
],
Expand Down
16 changes: 5 additions & 11 deletions test/cassettes/cache_guidload_normal.json

Large diffs are not rendered by default.

60 changes: 21 additions & 39 deletions test/cassettes/cache_logbook.json

Large diffs are not rendered by default.

21 changes: 6 additions & 15 deletions test/cassettes/cache_logpage.json

Large diffs are not rendered by default.

33 changes: 11 additions & 22 deletions test/cassettes/cache_non-ascii.json

Large diffs are not rendered by default.

Loading

0 comments on commit cfac3fc

Please sign in to comment.