Added __str__ to place

This commit is contained in:
Rhet Turnbull
2020-03-21 17:38:30 -07:00
parent 066215621d
commit ad58b03f2d
4 changed files with 49 additions and 2 deletions

View File

@@ -1,3 +1,3 @@
""" version info """ """ version info """
__version__ = "0.23.1" __version__ = "0.23.2"

View File

@@ -3,8 +3,9 @@
Provides reverse geolocation info for photos Provides reverse geolocation info for photos
""" """
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections import namedtuple from collections import namedtuple # pylint: disable=syntax-error
import yaml
from bpylist import archiver from bpylist import archiver
# postal address information, returned by PlaceInfo.address # postal address information, returned by PlaceInfo.address
@@ -362,6 +363,15 @@ class PlaceInfo4(PlaceInfo):
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __str__(self):
info = {
"name": self.name,
"names": self.names,
"country_code": self.country_code,
}
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
return strval
class PlaceInfo5(PlaceInfo): class PlaceInfo5(PlaceInfo):
""" Reverse geolocation place info for a photo (Photos >= 5) """ """ Reverse geolocation place info for a photo (Photos >= 5) """
@@ -431,3 +441,15 @@ class PlaceInfo5(PlaceInfo):
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)
def __str__(self):
info = {
"name": self.name,
"names": self.names,
"country_code": self.country_code,
"ishome": self.ishome,
"address_str": self.address_str,
"address": str(self.address),
}
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
return strval

View File

@@ -92,3 +92,16 @@ def test_place_no_place_info():
photo = photosdb.photos(uuid=[UUID_DICT["no_place"]])[0] photo = photosdb.photos(uuid=[UUID_DICT["no_place"]])[0]
assert photo.place is None assert photo.place is None
def test_place_str():
# test __str__
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
assert (
str(photo.place)
== "PlaceInfo(name='2038 18th St NW', names='['2038 18th St NW', 'Adams Morgan', 'Washington', 'Washington', 'Washington', 'District of Columbia', 'United States']', country_code='US', ishome='False', address_str='2038 18th St NW, Washington, DC 20009, United States', address='PostalAddress(street='2038 18th St NW', sub_locality='Adams Morgan', city='Washington', sub_administrative_area=None, state='DC', postal_code='20009', country='United States', iso_country_code='US')')"
)

View File

@@ -45,3 +45,15 @@ def test_place_no_place_info():
photo = photosdb.photos(uuid=[UUID_DICT["no_place"]])[0] photo = photosdb.photos(uuid=[UUID_DICT["no_place"]])[0]
assert photo.place is None assert photo.place is None
def test_place_str():
# test __str__
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photo = photosdb.photos(uuid=[UUID_DICT["place_uk"]])[0]
assert (
str(photo.place)
== "PlaceInfo(name='St James's Park', names='[\"St James's Park\", 'Westminster', 'London', 'England', 'United Kingdom']', country_code='GB')"
)