python3 获取/备份 iPhone icloud云端 中相关数据

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/baidu_39416074/article/details/80951875

PyiCloud是一个允许pythonistas与iCloud webservices交互的模块。它由奇妙的请求 HTTP库提供支持。

PyiCloud的核心是使用您的用户名和密码连接到iCloud,然后针对其API执行日历和iPhone查询。

pip install pythonistas
pip install bitstring
pip install keyring

photos.py 中需注意 python2 和python3 urllib 的区别

# import urllib
from urllib import parse
# 'url': urllib.unquote(url),
'url': parse.unquote(url),

认证

>>> from pyicloud import PyiCloudService
>>> api = PyiCloudService('[email protected]', 'password')

如果用户名/密码组合无效,则抛出PyiCloudFailedLoginException异常。

您还可以使用命令行工具将密码存储在系统密钥环中:

>>> icloud [email protected]
ICloud Password for [email protected]:
Save password in keyring? (y/N)

如果要删除存储在系统密钥环中的密码,可以使用--delete-from-keyring命令行选项清除存储的密码:

>>> api = PyiCloudService('[email protected]')

双重身份认证

扫描二维码关注公众号,回复: 3909354 查看本文章

如果想关闭iphone双重认证 详见关闭iphone双重身份认证方法

if api.requires_2fa:
    print("Two-factor authentication required. Your trusted devices are:")

    devices = api.trusted_devices
    for i, device in enumerate(devices):
        print("  %s: %s" % (i, device.get('deviceName',
                                          "SMS to %s" % device.get('phoneNumber'))))

    device = click.prompt('Which device would you like to use?', default=0)
    device = devices[device]
    if not api.send_verification_code(device):
        print("Failed to send verification code")
        sys.exit(1)

    code = click.prompt('Please enter validation code')
    if not api.validate_verification_code(device, code):
        print("Failed to verify verification code")
        sys.exit(1)

往来

您可以通过contacts属性访问您的iCloud联系人/地址簿:

for c in api.contacts.all():
    print(c)
    print(c.get('firstName'), c.get('phones'))
        

设备

您可以使用devices属性列出与您的帐户关联的设备:

>>> api.devices
{
u'i9vbKRGIcLYqJnXMd1b257kUWnoyEBcEh6yM + IfmiMLh7BmOpALS + w =​​=':<AppleDevice(iPhone 4S:Johnny Appleseed的iPhone)>,
u'reGYDh9XwqNWTGIhNBuEwP1ds0F / Lg5t / fxNbI4V939hhXawByErk + HYVNSUzmWV':<AppleDevice(MacBook Air 11“:Johnny Appleseed的MacBook Air)>
}

并且您可以通过索引或ID来访问各个设备:

>>> api.devices[0]
<AppleDevice(iPhone 4S: Johnny Appleseed's iPhone)>
>>> api.devices['i9vbKRGIcLYqJnXMd1b257kUWnoyEBcEh6yM+IfmiMLh7BmOpALS+w==']
<AppleDevice(iPhone 4S: Johnny Appleseed's iPhone)>

等等。。。 如果想了解更多 请 详见 pyicloud 0.9.1 开发文档

猜你喜欢

转载自blog.csdn.net/baidu_39416074/article/details/80951875