Merge pull request #57 from torarnv/various-cleanup-fixes
Various cleanup fixes
This commit is contained in:
commit
c0a597986e
6 changed files with 11 additions and 26 deletions
16
README.rst
16
README.rst
|
@ -15,18 +15,18 @@ At its core, PyiCloud connects to iCloud using your username and password, then
|
||||||
Authentication
|
Authentication
|
||||||
==============
|
==============
|
||||||
|
|
||||||
Authentication is as simple as passing your username and password to the `PyiCloudService` class:
|
Authentication is as simple as passing your username and password to the ``PyiCloudService`` class:
|
||||||
|
|
||||||
>>> from pyicloud import PyiCloudService
|
>>> from pyicloud import PyiCloudService
|
||||||
>>> api = PyiCloudService('jappleseed@apple.com', 'password')
|
>>> api = PyiCloudService('jappleseed@apple.com', 'password')
|
||||||
|
|
||||||
In the event that the username/password combination is invalid, a `PyiCloudFailedLoginException` exception is thrown.
|
In the event that the username/password combination is invalid, a ``PyiCloudFailedLoginException`` exception is thrown.
|
||||||
|
|
||||||
=======
|
=======
|
||||||
Devices
|
Devices
|
||||||
=======
|
=======
|
||||||
|
|
||||||
You can list which devices associated with your account by using the `devices` property:
|
You can list which devices associated with your account by using the ``devices`` property:
|
||||||
|
|
||||||
>>> api.devices
|
>>> api.devices
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ and you can access individual devices by either their index, or their ID:
|
||||||
>>> api.devices['i9vbKRGIcLYqJnXMd1b257kUWnoyEBcEh6yM+IfmiMLh7BmOpALS+w==']
|
>>> api.devices['i9vbKRGIcLYqJnXMd1b257kUWnoyEBcEh6yM+IfmiMLh7BmOpALS+w==']
|
||||||
<AppleDevice(iPhone 4S: Johnny Appleseed's iPhone)>
|
<AppleDevice(iPhone 4S: Johnny Appleseed's iPhone)>
|
||||||
|
|
||||||
or, as a shorthand if you have only one associated apple device, you can simply use the `iphone` property to access the first device associated with your account:
|
or, as a shorthand if you have only one associated apple device, you can simply use the ``iphone`` property to access the first device associated with your account:
|
||||||
|
|
||||||
>>> api.iphone
|
>>> api.iphone
|
||||||
<AppleDevice(iPhone 4S: Johnny Appleseed's iPhone)>
|
<AppleDevice(iPhone 4S: Johnny Appleseed's iPhone)>
|
||||||
|
@ -134,7 +134,7 @@ Note: These contacts do not include contacts federated from e.g. Facebook, only
|
||||||
File Storage (Ubiquity)
|
File Storage (Ubiquity)
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
You can access documents stored in your iCloud account by using the `files` property's `dir` method:
|
You can access documents stored in your iCloud account by using the ``files`` property's ``dir`` method:
|
||||||
|
|
||||||
>>> api.files.dir()
|
>>> api.files.dir()
|
||||||
[u'.do-not-delete',
|
[u'.do-not-delete',
|
||||||
|
@ -165,12 +165,12 @@ datetime.datetime(2012, 9, 13, 2, 26, 17)
|
||||||
>>> api.files['com~apple~Notes']['Documents']['Some Document'].type
|
>>> api.files['com~apple~Notes']['Documents']['Some Document'].type
|
||||||
u'file'
|
u'file'
|
||||||
|
|
||||||
And when you have a file that you'd like to download, the `open` method will return a response object from which you can read the `content`.
|
And when you have a file that you'd like to download, the ``open`` method will return a response object from which you can read the ``content``.
|
||||||
|
|
||||||
>>> api.files['com~apple~Notes']['Documents']['Some Document'].open().content
|
>>> api.files['com~apple~Notes']['Documents']['Some Document'].open().content
|
||||||
'Hello, these are the file contents'
|
'Hello, these are the file contents'
|
||||||
|
|
||||||
Note: the object returned from the above `open` method is a `response object <http://www.python-requests.org/en/latest/api/#classes>`_ and the `open` method can accept any parameters you might normally use in a request using `requests <https://github.com/kennethreitz/requests>`_.
|
Note: the object returned from the above ``open`` method is a `response object <http://www.python-requests.org/en/latest/api/#classes>`_ and the ``open`` method can accept any parameters you might normally use in a request using `requests <https://github.com/kennethreitz/requests>`_.
|
||||||
|
|
||||||
For example, if you know that the file you're opening has JSON content:
|
For example, if you know that the file you're opening has JSON content:
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ For example, if you know that the file you're opening has JSON content:
|
||||||
>>> api.files['com~apple~Notes']['Documents']['information.json'].open().json()['How much we love you']
|
>>> api.files['com~apple~Notes']['Documents']['information.json'].open().json()['How much we love you']
|
||||||
'lots'
|
'lots'
|
||||||
|
|
||||||
Or, if you're downloading a particularly large file, you may want to use the `stream` keyword argument, and read directly from the raw response object:
|
Or, if you're downloading a particularly large file, you may want to use the ``stream`` keyword argument, and read directly from the raw response object:
|
||||||
|
|
||||||
>>> download = api.files['com~apple~Notes']['Documents']['big_file.zip'].open(stream=True)
|
>>> download = api.files['com~apple~Notes']['Documents']['big_file.zip'].open(stream=True)
|
||||||
>>> with open('downloaded_file.zip', 'wb') as opened_file:
|
>>> with open('downloaded_file.zip', 'wb') as opened_file:
|
||||||
|
|
|
@ -40,13 +40,10 @@ class PyiCloudService(object):
|
||||||
self.user = {'apple_id': apple_id, 'password': password}
|
self.user = {'apple_id': apple_id, 'password': password}
|
||||||
|
|
||||||
self._home_endpoint = 'https://www.icloud.com'
|
self._home_endpoint = 'https://www.icloud.com'
|
||||||
self._setup_endpoint = 'https://p12-setup.icloud.com/setup/ws/1'
|
self._setup_endpoint = 'https://setup.icloud.com/setup/ws/1'
|
||||||
self._push_endpoint = 'https://p12-pushws.icloud.com'
|
|
||||||
|
|
||||||
self._base_login_url = '%s/login' % self._setup_endpoint
|
self._base_login_url = '%s/login' % self._setup_endpoint
|
||||||
self._base_validate_url = '%s/validate' % self._setup_endpoint
|
self._base_validate_url = '%s/validate' % self._setup_endpoint
|
||||||
self._base_system_url = '%s/system/version.json' % self._home_endpoint
|
|
||||||
self._base_webauth_url = '%s/refreshWebAuth' % self._push_endpoint
|
|
||||||
|
|
||||||
if cookie_directory:
|
if cookie_directory:
|
||||||
self._cookie_directory = os.path.expanduser(
|
self._cookie_directory = os.path.expanduser(
|
||||||
|
@ -61,9 +58,8 @@ class PyiCloudService(object):
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.verify = verify
|
self.session.verify = verify
|
||||||
self.session.headers.update({
|
self.session.headers.update({
|
||||||
'host': 'setup.icloud.com',
|
'Origin': self._home_endpoint,
|
||||||
'origin': self._home_endpoint,
|
'Referer': '%s/' % self._home_endpoint,
|
||||||
'referer': '%s/' % self._home_endpoint,
|
|
||||||
'User-Agent': 'Opera/9.52 (X11; Linux i686; U; en)'
|
'User-Agent': 'Opera/9.52 (X11; Linux i686; U; en)'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,6 @@ class CalendarService(object):
|
||||||
Fetches a single event's details by specifying a pguid
|
Fetches a single event's details by specifying a pguid
|
||||||
(a calendar) and a guid (an event's ID).
|
(a calendar) and a guid (an event's ID).
|
||||||
"""
|
"""
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
|
||||||
self.session.headers.update({'host': host})
|
|
||||||
params = dict(self.params)
|
params = dict(self.params)
|
||||||
params.update({'lang': 'en-us', 'usertz': self.get_system_tz()})
|
params.update({'lang': 'en-us', 'usertz': self.get_system_tz()})
|
||||||
url = '%s/%s/%s' % (self._calendar_event_detail_url, pguid, guid)
|
url = '%s/%s/%s' % (self._calendar_event_detail_url, pguid, guid)
|
||||||
|
@ -78,8 +76,6 @@ class CalendarService(object):
|
||||||
from_dt = datetime(today.year, today.month, first_day)
|
from_dt = datetime(today.year, today.month, first_day)
|
||||||
if not to_dt:
|
if not to_dt:
|
||||||
to_dt = datetime(today.year, today.month, last_day)
|
to_dt = datetime(today.year, today.month, last_day)
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
|
||||||
self.session.headers.update({'host': host})
|
|
||||||
params = dict(self.params)
|
params = dict(self.params)
|
||||||
params.update({
|
params.update({
|
||||||
'lang': 'en-us',
|
'lang': 'en-us',
|
||||||
|
|
|
@ -22,8 +22,6 @@ class ContactsService(object):
|
||||||
Refreshes the ContactsService endpoint, ensuring that the
|
Refreshes the ContactsService endpoint, ensuring that the
|
||||||
contacts data is up-to-date.
|
contacts data is up-to-date.
|
||||||
"""
|
"""
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
|
||||||
self.session.headers.update({'host': host})
|
|
||||||
params_contacts = dict(self.params)
|
params_contacts = dict(self.params)
|
||||||
params_contacts.update({
|
params_contacts.update({
|
||||||
'clientVersion': '2.1',
|
'clientVersion': '2.1',
|
||||||
|
|
|
@ -33,8 +33,6 @@ class FindMyiPhoneServiceManager(object):
|
||||||
This ensures that the location data is up-to-date.
|
This ensures that the location data is up-to-date.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
|
||||||
self.session.headers.update({'host': host})
|
|
||||||
req = self.session.post(
|
req = self.session.post(
|
||||||
self._fmip_refresh_url,
|
self._fmip_refresh_url,
|
||||||
params=self.params,
|
params=self.params,
|
||||||
|
|
|
@ -13,9 +13,6 @@ class UbiquityService(object):
|
||||||
self._service_root = service_root
|
self._service_root = service_root
|
||||||
self._node_url = '/ws/%s/%s/%s'
|
self._node_url = '/ws/%s/%s/%s'
|
||||||
|
|
||||||
host = self._service_root.split('//')[1].split(':')[0]
|
|
||||||
self.session.headers.update({'host': host})
|
|
||||||
|
|
||||||
def get_node_url(self, id, variant='item'):
|
def get_node_url(self, id, variant='item'):
|
||||||
return self._service_root + self._node_url % (
|
return self._service_root + self._node_url % (
|
||||||
self.params['dsid'],
|
self.params['dsid'],
|
||||||
|
|
Loading…
Reference in a new issue