Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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 = []
Add Comment
Please, Sign In to add comment