diff --git a/pycaching/geo.py b/pycaching/geo.py index 694b8de..9f83154 100644 --- a/pycaching/geo.py +++ b/pycaching/geo.py @@ -113,7 +113,7 @@ def from_tile(cls, tile, tile_point=None): else: dx, dy = 0, 0 - n = 2.0 ** tile.z + n = 2.0**tile.z lon_deg = (tile.x + dx) / n * 360.0 - 180.0 lat_rad = math.atan(math.sinh(math.pi * (1 - 2 * (tile.y + dy) / n))) lat_deg = math.degrees(lat_rad) @@ -132,7 +132,7 @@ def to_tile(self, geocaching, zoom): lat_deg = self.latitude lon_deg = self.longitude lat_rad = math.radians(lat_deg) - n = 2.0 ** zoom + n = 2.0**zoom x = int((lon_deg + 180.0) / 360.0 * n) y = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n) return Tile(geocaching, x, y, zoom) diff --git a/pycaching/geocaching.py b/pycaching/geocaching.py index dc269e6..8caa6c3 100644 --- a/pycaching/geocaching.py +++ b/pycaching/geocaching.py @@ -144,7 +144,7 @@ def login(self, username=None, password=None): post = {"UsernameOrEmail": username, "Password": password, token_field_name: token_value} # login to the site - logging.debug("Submiting login form.") + logging.debug("Submitting login form.") after_login_page = self._request(self._urls["login_page"], method="POST", data=post, login_check=False) logging.debug("Checking the result.") diff --git a/pycaching/trackable.py b/pycaching/trackable.py index 37f37e1..3ce6499 100644 --- a/pycaching/trackable.py +++ b/pycaching/trackable.py @@ -152,8 +152,10 @@ def type(self): return self._type @type.setter - def type(self, type): - self._type = type.strip() + def type(self, type_): + if type_ is not None: + type_ = type_.strip() + self._type = type_ def get_KML(self): """Return the KML route of the trackable. @@ -171,7 +173,7 @@ def load(self): This method is called automatically when you access a property which isn't yet filled in (so-called "lazy loading"). You don't have to call it explicitly. - :raise .LoadError: If trackable loading fails (probably because of not existing cache). + :raise .LoadError: If trackable loading fails (probably because of not existing trackable). """ # pick url based on what info we have right now if hasattr(self, "url"): diff --git a/pyproject.toml b/pyproject.toml index 4ba5ae1..8cc85a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ dev = [ "pytest-cov ~= 3.0", "betamax ~= 0.8", "betamax-serializers ~= 0.2", - "black ~= 21.10b0", + "black ~= 22.6.0", "flake8 ~= 4.0", "isort ~= 5.10" ] diff --git a/test/cassettes/trackable_load__existing_type.json b/test/cassettes/trackable_load__existing_type.json new file mode 100644 index 0000000..eaf4b65 --- /dev/null +++ b/test/cassettes/trackable_load__existing_type.json @@ -0,0 +1,77 @@ +{ + "http_interactions": [ + { + "recorded_at": "2022-08-21T16:42:52", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "gspkauth=; __RequestVerificationToken=" + ], + "User-Agent": [ + "python-requests/2.28.1" + ] + }, + "method": "GET", + "uri": "https://www.geocaching.com/track/details.aspx?tracker=TB1KEZ9" + }, + "response": { + "body": { + "encoding": "utf-8", + "string": "\r\n\r\n\r\n\r\n\r\n \r\n \r\n\t(TB1KEZ9) SwedenHawk Geocoin - Lilagul #2: SwedenHawk Geocoin\r\n\n \n\r\n\r\n\r\n \r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \n \n\r\n\r\n \r\n\r\n \r\n\r\n \n \n \n \r\n\n \n\r\n\r\n \r\n\r\n
\r\n
\r\n\r\n\r\n\r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n
\r\n\r\n\t\r\n
\r\n \r\n\r\n \r\n \r\n \r\n\r\n Skip to content\r\n\r\n \r\n\r\n \r\n
\r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n \r\n
\r\n\r\n
\r\n \r\n \r\n \r\n
\r\n \r\n\r\n
\r\n\t\r\n \n
\r\n\t\t\n \n\n

\n \"SwedenHawk Geocoin\"\n Lilagul #2: SwedenHawk Geocoin\n

\n \n \n\n \r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t
Trackable Options
\n \"\"/\n Found it? Log it!
\n \"\"\n Watch This Trackable Item
\n \"\"\n Printable information sheet to attach to Lilagul #2: SwedenHawk Geocoin\n Print Info Sheet
\n \"\"\n View in Google Earth
\n \n
\n\n
\n Owner:\n
\n\n
\n lilagul\n \n \n \n Send Message to Owner\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n Message this owner\n \n
\n\n \n\n
\n Released:\n
\n\n
\n Tuesday, May 29, 2007\n
\n\n \n \n\n
\n Origin:\n
\n\n
\n Germany\n
\n\n \n\n
\n Recently Spotted:
\n\n
\n In the hands of Alvis02.
\n\n
\n

\n \n

\n

\n The owner hasn't set their collectible preference.\n

\n

\n Use TB1KEZ9 to reference this item.\n

\n

\n \n First time logging a Trackable? Click here.\n \n

\n

\n Current Goal\n

\n
\n

\n There is currently no goal for this item.\n

\n
\n\n

\n About This Item\n

\n
\n

\n \n

\n

\n No additional details available.\n

\n
\n\n
\n
\n

\n

Gallery Images related to Lilagul #2: SwedenHawk Geocoin

    View 1 Gallery Image\n

    \n \n

    \n Tracking History (10277.6km ) View Map\n

    \n\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    \n \"Discovered 5/30/2017\n \n smartdiver discovered it\n \n \n  \n \n Visit Log\n
    \n

    Es ist an der Zeit, mal alle gesehenen Trackables nachzuloggen.
    \nDiesen Coin/TB habe ich mal irgendwo auf einem Event, in einem Cache, einem Logbuch oder im Internet gesehen. Danke f\u00fcr's discovern lassen.
    \n+++++++++++++++++++++++++++++++++++++++++++++++
    \nIt is finally time to log all seen trackables.
    \nThis Coin/TB I have seen anywhere at an event, in a cache, in a log book or on the Internet. Thanks for sharing.

    \n
    \n \n
    \n \"Retrieve 7/17/2015\n \n Alvis02 retrieved it from Vildhussen\n \n J\u00e4mtland, Sweden\n  \n \n Visit Log\n
    \n

    Tar med denna geocoin till Gotland!

    \n
    \n \n
    \n \"Dropped 7/15/2015\n \n lundwall placed it in Vildhussen\n \n J\u00e4mtland, Sweden\n - 6.98 km \n \n Visit Log\n
    \n

    Dropped in Vildhussen

    \n
    \n \n
    \n \"Visited\" 7/14/2015\n \n lundwall took it to Take a break at Hanneforsen\n \n J\u00e4mtland, Sweden\n - 595.32 km \n \n Visit Log\n
    \n

    Visited Take a break at Hanneforsen

    \n
    \n \n
    \n \"Retrieve 7/10/2015\n \n lundwall retrieved it from Lysekil TB-Hotel\n \n V\u00e4stra G\u00f6taland, Sweden\n  \n \n Visit Log\n
    \n

    Northbound!

    \n
    \n \n
    \n \"Dropped 7/8/2015\n \n bjazze placed it in Lysekil TB-Hotel\n \n V\u00e4stra G\u00f6taland, Sweden\n - 37.2 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 7/7/2015\n \n bjazze took it to Stefans kulle\n \n V\u00e4stra G\u00f6taland, Sweden\n - 172.38 meters \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 7/7/2015\n \n bjazze took it to Speker\u00f6ds TB Hotel\n \n V\u00e4stra G\u00f6taland, Sweden\n - 213.24 meters \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 7/7/2015\n \n bjazze took it to Speker\u00f6ds Rastplats\n \n V\u00e4stra G\u00f6taland, Sweden\n - 160.52 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 7/6/2015\n \n bjazze took it to N\u00e4ra Golf 7\n \n Halland, Sweden\n - 1.26 km \n \n Visit Log\n
    \n
    \n \n
    \n data on this page is cached for 3 mins\n
    \n \n\n\n

    \n \n

    \n\n\n \n \r\n\t
    \n \n \n \n\r\n \r\n
    \r\n\r\n
    \r\n
    \r\n\t\r\n \r\n
    \r\n\r\n
    \r\n\r\n \r\n

    \r\n \r\n Advertising with Us\r\n \r\n

    \r\n \r\n
    \r\n
    \r\n
    \r\n
    \r\n\r\n \r\n\r\n \n\n\n\n\n\n\n\n\n\r\n\r\n \n \n \n \n \n \n\r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n\r\n
    \r\n \r\n
    \r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n" + }, + "headers": { + "Cache-Control": [ + "private" + ], + "Content-Length": [ + "47201" + ], + "Content-Type": [ + "text/html; charset=utf-8" + ], + "Date": [ + "Sun, 21 Aug 2022 16:42:51 GMT" + ], + "Request-Context": [ + "appId=cid-v1:019d82c2-5dd7-44cb-aa94-01e052f0d40c" + ], + "Set-Cookie": [ + "gspkauth=; domain=.geocaching.com; expires=Wed, 21-Sep-2022 16:42:52 GMT; path=/; secure; HttpOnly", + "Culture=en-US; path=/; secure; HttpOnly" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubDomains" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://www.geocaching.com/track/details.aspx?tracker=TB1KEZ9" + } + } + ], + "recorded_with": "betamax/0.8.1" +} \ No newline at end of file diff --git a/test/cassettes/trackable_load__missing_type.json b/test/cassettes/trackable_load__missing_type.json new file mode 100644 index 0000000..7b972a3 --- /dev/null +++ b/test/cassettes/trackable_load__missing_type.json @@ -0,0 +1,77 @@ +{ + "http_interactions": [ + { + "recorded_at": "2022-08-21T16:42:52", + "request": { + "body": { + "encoding": "utf-8", + "string": "" + }, + "headers": { + "Accept": [ + "*/*" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Connection": [ + "keep-alive" + ], + "Cookie": [ + "gspkauth=; Culture=en-US; __RequestVerificationToken=" + ], + "User-Agent": [ + "python-requests/2.28.1" + ] + }, + "method": "GET", + "uri": "https://www.geocaching.com/track/details.aspx?tracker=TB7WZD9" + }, + "response": { + "body": { + "encoding": "utf-8", + "string": "\r\n\r\n\r\n\r\n\r\n \r\n \r\n\t(TB7WZD9) Wedo Multi-Tool - Wedo Multi-Tool\r\n\n \n\r\n\r\n\r\n \r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \n \n\r\n\r\n \r\n\r\n \r\n\r\n \n \n \n \r\n\n \n\r\n\r\n \r\n\r\n
    \r\n
    \r\n\r\n\r\n\r\n\r\n
    \r\n\r\n\r\n\r\n\r\n\r\n
    \r\n\r\n\t\r\n
    \r\n \r\n\r\n \r\n \r\n \r\n\r\n Skip to content\r\n\r\n \r\n\r\n \r\n
    \r\n \r\n \r\n \r\n \r\n
    \r\n \r\n
    \r\n \r\n
    \r\n\r\n
    \r\n \r\n \r\n \r\n
    \r\n \r\n\r\n
    \r\n\t\r\n \n
    \r\n\t\t\n \n\n

    \n \n Wedo Multi-Tool\n

    \n \n \n\n \r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t
    Trackable Options
    \n \"\"/\n Found it? Log it!
    \n \"\"\n Watch This Trackable Item
    \n \"\"\n Printable information sheet to attach to Wedo Multi-Tool\n Print Info Sheet
    \n \"\"\n View in Google Earth
    \n \n
    \n\n
    \n Owner:\n
    \n\n
    \n Kamimieze\n \n \n \n Send Message to Owner\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n Message this owner\n \n
    \n\n \n\n
    \n Released:\n
    \n\n
    \n Sunday, 01 January 2017\n
    \n\n \n \n\n
    \n Origin:\n
    \n\n
    \n Bayern, Germany\n
    \n\n \n\n
    \n Recently Spotted:
    \n\n
    \n In the hands of the owner.
    \n\n
    \n

    \n \n

    \n

    \n This is collectible.\n

    \n

    \n Use TB7WZD9 to reference this item.\n

    \n

    \n \n First time logging a Trackable? Click here.\n \n

    \n

    \n Current Goal\n

    \n
    \n

    \n There is currently no goal for this item.\n

    \n
    \n\n

    \n About This Item\n

    \n
    \n

    \n \n

    \n

    \n No additional details available.\n

    \n
    \n\n
    \n
    \n

    \n \n

    \n \n

    \n Tracking History (27507.6km ) View Map\n

    \n\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
    \n \"Visited\" 12/5/2018\n \n Kamimieze took it to QR Bonus\n \n Bayern, Germany\n - 184.85 meters \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 12/5/2018\n \n Kamimieze took it to Die Sache mit QR\n \n Bayern, Germany\n - 168.23 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 12/4/2018\n \n Kamimieze took it to Valhalla's Geldautomat ( ATM )\n \n Hessen, Germany\n - 29.06 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 11/24/2018\n \n Kamimieze took it to A66 Autobahnparkplatz Weinberg\n \n Hessen, Germany\n - 151.31 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 11/15/2018\n \n Kamimieze took it to Bavaria-Ticket\n \n Bayern, Germany\n - 296.12 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 10/22/2018\n \n Kamimieze took it to Schloss B\u00fcrresheim 🏰\n \n Rheinland-Pfalz, Germany\n - 76.43 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 10/21/2018\n \n Kamimieze took it to Sieh Dich um\n \n Rheinland-Pfalz, Germany\n - 345.97 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 10/20/2018\n \n Kamimieze took it to Rathausplatz Augsburg\n \n Bayern, Germany\n - 346.07 km \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 10/20/2018\n \n Kamimieze took it to Porta Nigra - Fossilien an alter St\u00e4tte 🐌\n \n Rheinland-Pfalz, Germany\n - 22.37 meters \n \n Visit Log\n
    \n
    \n \n
    \n \"Visited\" 10/20/2018\n \n Kamimieze took it to Virtual Reward - Porta Nigra Trier\n \n Rheinland-Pfalz, Germany\n - 320.4 km \n \n Visit Log\n
    \n
    \n \n
    \n data on this page is cached for 3 mins\n
    \n \n\n\n

    \n \n

    \n\n\n \n \r\n\t
    \n \n \n \n\r\n \r\n
    \r\n\r\n
    \r\n
    \r\n\t\r\n \r\n
    \r\n\r\n
    \r\n\r\n \r\n

    \r\n \r\n Advertising with Us\r\n \r\n

    \r\n \r\n
    \r\n
    \r\n
    \r\n
    \r\n\r\n \r\n\r\n \n\n\n\n\n\n\n\n\n\r\n\r\n \n \n \n \n \n \n\r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n\r\n
    \r\n \r\n
    \r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n" + }, + "headers": { + "Cache-Control": [ + "private" + ], + "Content-Length": [ + "45437" + ], + "Content-Type": [ + "text/html; charset=utf-8" + ], + "Date": [ + "Sun, 21 Aug 2022 16:42:51 GMT" + ], + "Request-Context": [ + "appId=cid-v1:019d82c2-5dd7-44cb-aa94-01e052f0d40c" + ], + "Set-Cookie": [ + "gspkauth=; domain=.geocaching.com; expires=Wed, 21-Sep-2022 16:42:52 GMT; path=/; secure; HttpOnly", + "Culture=en-US; path=/; secure; HttpOnly" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubDomains" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "X-XSS-Protection": [ + "1" + ] + }, + "status": { + "code": 200, + "message": "OK" + }, + "url": "https://www.geocaching.com/track/details.aspx?tracker=TB7WZD9" + } + } + ], + "recorded_with": "betamax/0.8.1" +} \ No newline at end of file diff --git a/test/test_trackable.py b/test/test_trackable.py index e56d175..666cd35 100644 --- a/test/test_trackable.py +++ b/test/test_trackable.py @@ -146,3 +146,16 @@ def test_get_KML(self): self.assertTrue("#tbTravelStyle" in kml) self.assertTrue("1" in kml) self.assertTrue("" in kml) + + +class TestIssues(LoggedInTest): + def test_load__type(self): + with self.subTest("existing"): + trackable = Trackable(self.gc, "TB1KEZ9") + with self.recorder.use_cassette("trackable_load__existing_type"): + self.assertEqual("SwedenHawk Geocoin", trackable.type) + + with self.subTest("missing"): + trackable = Trackable(self.gc, "TB7WZD9") + with self.recorder.use_cassette("trackable_load__missing_type"): + self.assertEqual(None, trackable.type)