Last active
December 9, 2024 00:12
-
-
Save Tatsh/0b5a10a2d25f6c8466290401d2026055 to your computer and use it in GitHub Desktop.
Revisions
-
Tatsh revised this gist
Nov 6, 2017 . No changes.There are no files selected for viewing
-
Tatsh created this gist
Nov 6, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ #!/usr/bin/env python from __future__ import print_function import json import sys from authentication import authenticate from future.moves.urllib.parse import urlencode if __name__ == '__main__': username = sys.argv[1] password = sys.argv[2] smtp_username = smtp_password = smtp_host = smtp_port = smtp_no_tls = notification_email = None print('Logging in') icloud = authenticate(username, password, smtp_username, smtp_password, smtp_host, smtp_port, smtp_no_tls, notification_email) photos = icloud.photos.all operations = [] url = '{}/records/modify?{}'.format(icloud.photos._service_endpoint, urlencode(icloud.photos.params)) headers = {'Content-type': 'text/plain'} seen_record_names = [] for photo in photos: # Avoid duplicate operations if photo._asset_record['recordName'] in seen_record_names: continue seen_record_names.append(photo._asset_record['recordName']) mr = {'fields': {'isDeleted': {'value': 1}}} mr['recordChangeTag'] = photo._asset_record['recordChangeTag'] mr['recordName'] = photo._asset_record['recordName'] mr['recordType'] = 'CPLAsset' op = dict( operationType='update', record=mr, ) operations.append(op) # Limit to 100 photos at a time if len(operations) >= 100: post_data = json.dumps(dict( atomic=True, desiredKeys=['isDeleted'], operations=operations, zoneID={'zoneName': 'PrimarySync'}, )) print('Deleting 100 photos') print(icloud.photos.session.post(url, data=post_data, headers=headers).json()) operations = []