The updated photos-module in the new Pythonista versions is great, but I wonder about the start and end date you can now retrieve for an album (regular, smart, moments). I notice that I only get valid dates back for moments, not for regular albums or smart albums: in the latter two cases the return value is None. Is this by design (I know Apple's API works the same way) or is this a small glitch in Pythonista's implementation?
Forum Archive
Photos module - album start date / end date
[deleted]
Jun 17, 2016 - 17:24
omz
Jun 17, 2016 - 18:20
As far as I understand Apple's API, that's by design.
omz
Jun 17, 2016 - 19:05
Just looked up Apple's documentation again, and it says about startDate (equivalent to start_date in Pythonista):
This property applies only to asset collections whose type is PHAssetCollectionTypeMoment. For other asset collection types, this property’s value is nil.
[deleted]
Jun 17, 2016 - 19:30
@omz Thanks for your answer, good to know. Using the assets list of a regular or smart album in combination with the creation_date of an asset it's easy to get the start date and end date of any album: for moments there's also the other alternative.
[deleted]
Jun 17, 2016 - 19:47
So this is what I'm using to get the start date and end date of any album, works great and takes advantage of the fact that the assets list is ordered in ascending order by date:
def get_album_dates(album:photos.AssetCollection) -> (datetime.datetime, datetime.datetime):
assets = album.assets
if len(assets) == 0:
return (None, None)
else:
return (assets[0].creation_date, assets[-1].creation_date)