pytolino 0.1.5__tar.gz → 1.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytolino
3
- Version: 0.1.5
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
 
@@ -26,7 +26,7 @@ Before being able to send requests, you need to register your computer on which
26
26
  client.register() # do this only once!
27
27
  client.logout()
28
28
 
29
- You can then upload or delete ebook on your cloud:
29
+ You can then upload, add to a collection or delete ebook on your cloud:
30
30
 
31
31
  .. code-block:: python
32
32
 
@@ -34,7 +34,9 @@ You can then upload or delete ebook on your cloud:
34
34
  client = Client()
35
35
  client.login(USERNAME, PASSWORD)
36
36
  ebook_id = client.upload(EPUB_FILE_PATH) # return a unique id that can be used for reference
37
+ client.add_collection(epub_id, 'science fiction') # add the previous book to the collection science-fiction
37
38
  client.delete_ebook(epub_id) # delete the previousely uploaded ebook
39
+ inventory = client.get_inventory() # get a list of all the books on the cloud and their metadata
38
40
  client.logout()
39
41
 
40
42
 
@@ -57,6 +59,8 @@ Features
57
59
  * unregister device
58
60
  * upload ebook
59
61
  * delete ebook from the cloud
62
+ * add a book to a collection
63
+ * download inventory
60
64
  * more to come...
61
65
 
62
66
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pytolino"
7
- version = "0.1.5"
7
+ version = "1.1"
8
8
  authors = [
9
9
  {name="Imam Usmani"},
10
10
  ]
@@ -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: 0.1.5
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
 
@@ -137,6 +137,16 @@ def upload_test():
137
137
 
138
138
  client.logout()
139
139
 
140
+ def collection_test():
141
+ with open(EPUB_ID_PATH, 'r') as myfile:
142
+ epub_id = myfile.read()
143
+
144
+ username, password = get_credentials()
145
+ client = Client()
146
+ client.login(username, password)
147
+ client.add_to_collection(epub_id, 'test_coll')
148
+ client.logout()
149
+
140
150
 
141
151
  def delete_test():
142
152
 
@@ -150,5 +160,26 @@ def delete_test():
150
160
  client.logout()
151
161
 
152
162
 
163
+ def inventory_test():
164
+
165
+ username, password = get_credentials()
166
+ client = Client()
167
+ client.login(username, password)
168
+ inventory = client.get_inventory()
169
+ client.logout()
170
+ print(inventory[0].keys())
171
+ metadata = inventory[0]['epubMetaData']
172
+ print(metadata.keys())
173
+
174
+ def delete_test():
175
+
176
+ with open(EPUB_ID_PATH, 'r') as myfile:
177
+ epub_id = myfile.read()
178
+
179
+ username, password = get_credentials()
180
+ client = Client()
181
+ client.login(username, password)
182
+ client.delete_ebook(epub_id)
183
+ client.logout()
153
184
  if __name__ == '__main__':
154
- delete_test()
185
+ inventory_test()
File without changes
File without changes
File without changes