Added as_dict to PlaceInfo
This commit is contained in:
@@ -493,6 +493,14 @@ class PlaceInfo4(PlaceInfo):
|
|||||||
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
|
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
|
||||||
return strval
|
return strval
|
||||||
|
|
||||||
|
def as_dict(self):
|
||||||
|
info = {
|
||||||
|
"name": self.name,
|
||||||
|
"names": self.names._asdict(),
|
||||||
|
"country_code": self.country_code,
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
|
||||||
|
|
||||||
class PlaceInfo5(PlaceInfo):
|
class PlaceInfo5(PlaceInfo):
|
||||||
""" Reverse geolocation place info for a photo (Photos >= 5) """
|
""" Reverse geolocation place info for a photo (Photos >= 5) """
|
||||||
@@ -624,3 +632,14 @@ class PlaceInfo5(PlaceInfo):
|
|||||||
}
|
}
|
||||||
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
|
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
|
||||||
return strval
|
return strval
|
||||||
|
|
||||||
|
def as_dict(self):
|
||||||
|
info = {
|
||||||
|
"name": self.name,
|
||||||
|
"names": self.names._asdict(),
|
||||||
|
"country_code": self.country_code,
|
||||||
|
"ishome": self.ishome,
|
||||||
|
"address_str": self.address_str,
|
||||||
|
"address": self.address._asdict(),
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
|||||||
@@ -10,6 +10,44 @@ UUID_DICT = {
|
|||||||
"no_place": "A9B73E13-A6F2-4915-8D67-7213B39BAE9F",
|
"no_place": "A9B73E13-A6F2-4915-8D67-7213B39BAE9F",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MAUI_DICT = {
|
||||||
|
"name": "Maui, Wailea, Hawai'i, United States",
|
||||||
|
"names": {
|
||||||
|
"field0": [],
|
||||||
|
"country": ["United States"],
|
||||||
|
"state_province": ["Hawai'i"],
|
||||||
|
"sub_administrative_area": ["Maui"],
|
||||||
|
"city": ["Wailea", "Kihei", "Kihei"],
|
||||||
|
"field5": [],
|
||||||
|
"additional_city_info": [],
|
||||||
|
"ocean": [],
|
||||||
|
"area_of_interest": [],
|
||||||
|
"inland_water": [],
|
||||||
|
"field10": [],
|
||||||
|
"region": ["Maui"],
|
||||||
|
"sub_throughfare": [],
|
||||||
|
"field13": [],
|
||||||
|
"postal_code": [],
|
||||||
|
"field15": [],
|
||||||
|
"field16": [],
|
||||||
|
"street_address": ["3700 Wailea Alanui Dr"],
|
||||||
|
"body_of_water": [],
|
||||||
|
},
|
||||||
|
"country_code": "US",
|
||||||
|
"ishome": False,
|
||||||
|
"address_str": "3700 Wailea Alanui Dr, Kihei, HI 96753, United States",
|
||||||
|
"address": {
|
||||||
|
"street": "3700 Wailea Alanui Dr",
|
||||||
|
"sub_locality": None,
|
||||||
|
"city": "Kihei",
|
||||||
|
"sub_administrative_area": "Maui",
|
||||||
|
"state_province": "HI",
|
||||||
|
"postal_code": "96753",
|
||||||
|
"country": "United States",
|
||||||
|
"iso_country_code": "US",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_place_place_info_1():
|
def test_place_place_info_1():
|
||||||
# test valid place info
|
# test valid place info
|
||||||
@@ -92,6 +130,17 @@ def test_place_no_place_info():
|
|||||||
assert photo.place is None
|
assert photo.place is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_place_place_info_as_dict():
|
||||||
|
# test PlaceInfo.as_dict()
|
||||||
|
import osxphotos
|
||||||
|
|
||||||
|
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||||
|
photo = photosdb.photos(uuid=[UUID_DICT["place_maui"]])[0]
|
||||||
|
|
||||||
|
assert isinstance(photo.place, osxphotos.placeinfo.PlaceInfo)
|
||||||
|
assert photo.place.as_dict() == MAUI_DICT
|
||||||
|
|
||||||
|
|
||||||
# def test_place_str():
|
# def test_place_str():
|
||||||
# # test __str__
|
# # test __str__
|
||||||
# import osxphotos
|
# import osxphotos
|
||||||
|
|||||||
@@ -5,6 +5,32 @@ PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db"
|
|||||||
|
|
||||||
UUID_DICT = {"place_uk": "3Jn73XpSQQCluzRBMWRsMA", "no_place": "15uNd7%8RguTEgNPKHfTWw"}
|
UUID_DICT = {"place_uk": "3Jn73XpSQQCluzRBMWRsMA", "no_place": "15uNd7%8RguTEgNPKHfTWw"}
|
||||||
|
|
||||||
|
UK_DICT = {
|
||||||
|
"name": "St James's Park, Westminster, United Kingdom",
|
||||||
|
"names": {
|
||||||
|
"field0": [],
|
||||||
|
"country": ["United Kingdom"],
|
||||||
|
"state_province": ["England"],
|
||||||
|
"sub_administrative_area": ["London"],
|
||||||
|
"city": ["Westminster"],
|
||||||
|
"field5": [],
|
||||||
|
"additional_city_info": [],
|
||||||
|
"ocean": [],
|
||||||
|
"area_of_interest": ["St James's Park"],
|
||||||
|
"inland_water": [],
|
||||||
|
"field10": [],
|
||||||
|
"region": [],
|
||||||
|
"sub_throughfare": [],
|
||||||
|
"field13": [],
|
||||||
|
"postal_code": [],
|
||||||
|
"field15": [],
|
||||||
|
"field16": [],
|
||||||
|
"street_address": [],
|
||||||
|
"body_of_water": [],
|
||||||
|
},
|
||||||
|
"country_code": "GB",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_place_place_info_1():
|
def test_place_place_info_1():
|
||||||
# test valid place info
|
# test valid place info
|
||||||
@@ -60,3 +86,13 @@ def test_place_str():
|
|||||||
"region=[], sub_throughfare=[], field13=[], postal_code=[], field15=[], "
|
"region=[], sub_throughfare=[], field13=[], postal_code=[], field15=[], "
|
||||||
"field16=[], street_address=[], body_of_water=[])', country_code='GB')"
|
"field16=[], street_address=[], body_of_water=[])', country_code='GB')"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_place_as_dict():
|
||||||
|
# test PlaceInfo.as_dict()
|
||||||
|
import osxphotos
|
||||||
|
|
||||||
|
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||||
|
photo = photosdb.photos(uuid=[UUID_DICT["place_uk"]])[0]
|
||||||
|
assert photo.place is not None
|
||||||
|
assert isinstance(photo.place, osxphotos.placeinfo.PlaceInfo)
|
||||||
|
assert photo.place.as_dict() == UK_DICT
|
||||||
|
|||||||
Reference in New Issue
Block a user