pytolino 0.1.5__py3-none-any.whl → 1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytolino/tolino_cloud.py +77 -0
- {pytolino-0.1.5.dist-info → pytolino-1.1.dist-info}/METADATA +6 -2
- pytolino-1.1.dist-info/RECORD +8 -0
- {pytolino-0.1.5.dist-info → pytolino-1.1.dist-info}/WHEEL +1 -1
- pytolino-0.1.5.dist-info/RECORD +0 -8
- {pytolino-0.1.5.dist-info → pytolino-1.1.dist-info}/LICENSE +0 -0
- {pytolino-0.1.5.dist-info → pytolino-1.1.dist-info}/top_level.txt +0 -0
pytolino/tolino_cloud.py
CHANGED
|
@@ -7,6 +7,7 @@ import platform
|
|
|
7
7
|
import logging
|
|
8
8
|
from urllib.parse import urlparse, parse_qs
|
|
9
9
|
import json
|
|
10
|
+
import time
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
import requests
|
|
@@ -287,6 +288,82 @@ class Client(object):
|
|
|
287
288
|
raise PytolinoException(
|
|
288
289
|
f'unregister {device_id} failed: reason unknown.')
|
|
289
290
|
|
|
291
|
+
def get_inventory(self):
|
|
292
|
+
"""download a list of the books on the cloud and their information
|
|
293
|
+
:returns: list of dict describing the book, with a epubMetaData dict
|
|
294
|
+
|
|
295
|
+
"""
|
|
296
|
+
|
|
297
|
+
host_response = self.session.get(
|
|
298
|
+
self.server_settings['inventory_url'],
|
|
299
|
+
params={'strip': 'true'},
|
|
300
|
+
headers={
|
|
301
|
+
't_auth_token': self.access_token,
|
|
302
|
+
'hardware_id': self.hardware_id,
|
|
303
|
+
'reseller_id': self.server_settings['partner_id'],
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
self._log_requests(host_response)
|
|
308
|
+
if host_response.status_code != 200:
|
|
309
|
+
raise PytolinoException('invetory request failed')
|
|
310
|
+
|
|
311
|
+
try:
|
|
312
|
+
j = host_response.json()
|
|
313
|
+
except requests.JSONDecodeError:
|
|
314
|
+
raise PytolinoException(
|
|
315
|
+
'inventory list request failed because of json error.'
|
|
316
|
+
)
|
|
317
|
+
else:
|
|
318
|
+
try:
|
|
319
|
+
publication_inventory = j['PublicationInventory']
|
|
320
|
+
uploaded_ebooks = publication_inventory['edata']
|
|
321
|
+
purchased_ebook = publication_inventory['ebook']
|
|
322
|
+
except KeyError:
|
|
323
|
+
raise PytolinoException(
|
|
324
|
+
'inventory list request failed because',
|
|
325
|
+
'of key error in json.',
|
|
326
|
+
)
|
|
327
|
+
else:
|
|
328
|
+
inventory = uploaded_ebooks + purchased_ebook
|
|
329
|
+
return inventory
|
|
330
|
+
|
|
331
|
+
def add_to_collection(self, book_id, collection_name):
|
|
332
|
+
"""add a book to a collection on the cloud
|
|
333
|
+
|
|
334
|
+
:book_id: identify the book on the cloud
|
|
335
|
+
:collection_name: str name
|
|
336
|
+
|
|
337
|
+
"""
|
|
338
|
+
|
|
339
|
+
payload = {
|
|
340
|
+
"revision": None,
|
|
341
|
+
"patches": [{
|
|
342
|
+
"op": "add",
|
|
343
|
+
"value": {
|
|
344
|
+
"modified": round(time.time() * 1000),
|
|
345
|
+
"name": collection_name,
|
|
346
|
+
"category": "collection",
|
|
347
|
+
},
|
|
348
|
+
"path": f"/publications/{book_id}/tags"
|
|
349
|
+
}]
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
host_response = self.session.patch(
|
|
353
|
+
self.server_settings['sync_data_url'],
|
|
354
|
+
data=json.dumps(payload),
|
|
355
|
+
headers={
|
|
356
|
+
'content-type': 'application/json',
|
|
357
|
+
't_auth_token': self.access_token,
|
|
358
|
+
'hardware_id': self.hardware_id,
|
|
359
|
+
'reseller_id': self.server_settings['partner_id'],
|
|
360
|
+
'client_type': 'TOLINO_WEBREADER',
|
|
361
|
+
}
|
|
362
|
+
)
|
|
363
|
+
self._log_requests(host_response)
|
|
364
|
+
if host_response.status_code != 200:
|
|
365
|
+
raise PytolinoException('add to collection failed')
|
|
366
|
+
|
|
290
367
|
def upload(self, file_path, name=None, extension=None):
|
|
291
368
|
"""upload an ebook to your cloud
|
|
292
369
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pytolino
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.1
|
|
4
4
|
Summary: client for tolino cloud
|
|
5
5
|
Author: Imam Usmani
|
|
6
6
|
Project-URL: Source Code, https://github.com/ImamAzim/pytolino
|
|
@@ -52,7 +52,7 @@ Before being able to send requests, you need to register your computer on which
|
|
|
52
52
|
client.register() # do this only once!
|
|
53
53
|
client.logout()
|
|
54
54
|
|
|
55
|
-
You can then upload or delete ebook on your cloud:
|
|
55
|
+
You can then upload, add to a collection or delete ebook on your cloud:
|
|
56
56
|
|
|
57
57
|
.. code-block:: python
|
|
58
58
|
|
|
@@ -60,7 +60,9 @@ You can then upload or delete ebook on your cloud:
|
|
|
60
60
|
client = Client()
|
|
61
61
|
client.login(USERNAME, PASSWORD)
|
|
62
62
|
ebook_id = client.upload(EPUB_FILE_PATH) # return a unique id that can be used for reference
|
|
63
|
+
client.add_collection(epub_id, 'science fiction') # add the previous book to the collection science-fiction
|
|
63
64
|
client.delete_ebook(epub_id) # delete the previousely uploaded ebook
|
|
65
|
+
inventory = client.get_inventory() # get a list of all the books on the cloud and their metadata
|
|
64
66
|
client.logout()
|
|
65
67
|
|
|
66
68
|
|
|
@@ -83,6 +85,8 @@ Features
|
|
|
83
85
|
* unregister device
|
|
84
86
|
* upload ebook
|
|
85
87
|
* delete ebook from the cloud
|
|
88
|
+
* add a book to a collection
|
|
89
|
+
* download inventory
|
|
86
90
|
* more to come...
|
|
87
91
|
|
|
88
92
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pytolino/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
pytolino/servers_settings.ini,sha256=F8wSIWwl4XhQJKrhhbHtLhpXtfaGI7ODoD-VReaseBQ,1496
|
|
3
|
+
pytolino/tolino_cloud.py,sha256=QeKp0lsQLi2HOvXS8XhIcRxKFoAwSoDndamn1mWFFuk,15852
|
|
4
|
+
pytolino-1.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
5
|
+
pytolino-1.1.dist-info/METADATA,sha256=EckIp1U_kMNm1cv8qxxqYcV2GQM9ZEbTt2wsEQPgQ0Y,2929
|
|
6
|
+
pytolino-1.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
7
|
+
pytolino-1.1.dist-info/top_level.txt,sha256=3stGCqihEMMqlWGkME45OTJ0Prg-FO_kl554rtYNeuU,9
|
|
8
|
+
pytolino-1.1.dist-info/RECORD,,
|
pytolino-0.1.5.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
pytolino/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
pytolino/servers_settings.ini,sha256=F8wSIWwl4XhQJKrhhbHtLhpXtfaGI7ODoD-VReaseBQ,1496
|
|
3
|
-
pytolino/tolino_cloud.py,sha256=2RpUaSRNbfht9FeUTr-S1I5xEI1Zs8eiAGyHuK26zXU,13040
|
|
4
|
-
pytolino-0.1.5.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
5
|
-
pytolino-0.1.5.dist-info/METADATA,sha256=WDvuEI-uO2JwZdsf_-8TvXxkdWLMM_O3N8aqlMcbnSk,2647
|
|
6
|
-
pytolino-0.1.5.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
|
|
7
|
-
pytolino-0.1.5.dist-info/top_level.txt,sha256=3stGCqihEMMqlWGkME45OTJ0Prg-FO_kl554rtYNeuU,9
|
|
8
|
-
pytolino-0.1.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|