pytolino 1.2__tar.gz → 1.5__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: 1.2
3
+ Version: 1.5
4
4
  Summary: client for tolino cloud
5
5
  Author: Imam Usmani
6
6
  Project-URL: Source Code, https://github.com/ImamAzim/pytolino
@@ -61,6 +61,7 @@ You can then upload, add to a collection or delete ebook on your cloud:
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
63
  client.add_collection(epub_id, 'science fiction') # add the previous book to the collection science-fiction
64
+ client.add_cover(epub_id, cover_path) # to upload a cover on the book.
64
65
  client.delete_ebook(epub_id) # delete the previousely uploaded ebook
65
66
  inventory = client.get_inventory() # get a list of all the books on the cloud and their metadata
66
67
  client.upload_metadata(epub_id, title='my title', author='someone') # you can upload various kind of metadata
@@ -77,6 +78,22 @@ if you want to unregister your computer:
77
78
  client.register() # now you will not be able to upload books from this computer
78
79
  client.logout()
79
80
 
81
+ By default, it will connect to 'www.buecher.de'. In principle you could change the partner with:
82
+
83
+ .. code-block:: python
84
+
85
+ client = Client(server_name='www.orelfuessli') # for example if you have an account at orel fuessli.
86
+
87
+ To get a list of the supported partners:
88
+
89
+ .. code-block:: python
90
+
91
+ from pytolino.tolino_cloud import PARTNERS
92
+ print(PARTNERS)
93
+
94
+ Unfortunately, the only supported partner now is 'www.buecher.de', because it has a different way of connection... So for now, the only solution is to create an account there and link it to your original account.
95
+
96
+
80
97
 
81
98
  Features
82
99
  ========
@@ -35,6 +35,7 @@ You can then upload, add to a collection or delete ebook on your cloud:
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
37
  client.add_collection(epub_id, 'science fiction') # add the previous book to the collection science-fiction
38
+ client.add_cover(epub_id, cover_path) # to upload a cover on the book.
38
39
  client.delete_ebook(epub_id) # delete the previousely uploaded ebook
39
40
  inventory = client.get_inventory() # get a list of all the books on the cloud and their metadata
40
41
  client.upload_metadata(epub_id, title='my title', author='someone') # you can upload various kind of metadata
@@ -51,6 +52,22 @@ if you want to unregister your computer:
51
52
  client.register() # now you will not be able to upload books from this computer
52
53
  client.logout()
53
54
 
55
+ By default, it will connect to 'www.buecher.de'. In principle you could change the partner with:
56
+
57
+ .. code-block:: python
58
+
59
+ client = Client(server_name='www.orelfuessli') # for example if you have an account at orel fuessli.
60
+
61
+ To get a list of the supported partners:
62
+
63
+ .. code-block:: python
64
+
65
+ from pytolino.tolino_cloud import PARTNERS
66
+ print(PARTNERS)
67
+
68
+ Unfortunately, the only supported partner now is 'www.buecher.de', because it has a different way of connection... So for now, the only solution is to create an account there and link it to your original account.
69
+
70
+
54
71
 
55
72
  Features
56
73
  ========
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pytolino"
7
- version = "1.2"
7
+ version = "1.5"
8
8
  authors = [
9
9
  {name="Imam Usmani"},
10
10
  ]
@@ -26,5 +26,4 @@ sync_data_url = https://bosh.pageplace.de/bosh/rest/sync-data?paths=publicati
26
26
  delete_url = https://bosh.pageplace.de/bosh/rest/deletecontent
27
27
  inventory_url = https://bosh.pageplace.de/bosh/rest/inventory/delta
28
28
  downloadinfo_url = https://bosh.pageplace.de/bosh/rest//cloud/downloadinfo/{}/{}/type/external-download
29
- [www.buecher.de.extra]
30
29
  form_send = 1
@@ -26,6 +26,8 @@ SERVERS_SETTINGS_FILE_PATH = os.path.join(
26
26
  servers_settings = configparser.ConfigParser()
27
27
  servers_settings.read(SERVERS_SETTINGS_FILE_PATH)
28
28
 
29
+ PARTNERS = servers_settings.sections()
30
+
29
31
 
30
32
  def main():
31
33
  print(SERVERS_SETTINGS_FILE_PATH)
@@ -113,7 +115,9 @@ class Client(object):
113
115
  def __init__(self, server_name='www.buecher.de'):
114
116
 
115
117
  if server_name not in servers_settings:
116
- raise PytolinoException(f'no partner {server_name} found')
118
+ raise PytolinoException(
119
+ f'the partner {server_name} was not found.'
120
+ f'please choose one of the list: {PARTNERS}')
117
121
 
118
122
  self.access_token = None
119
123
  self.refresh_token = None
@@ -122,6 +126,7 @@ class Client(object):
122
126
  self.server_settings = servers_settings[server_name]
123
127
  self.session = requests.session()
124
128
  self.browser = mechanize.Browser()
129
+ self.browser.set_handle_robots(False)
125
130
  self.server_name = server_name
126
131
 
127
132
  def login(self, username, password):
@@ -487,6 +492,40 @@ class Client(object):
487
492
  raise PytolinoException(
488
493
  f'delete {ebook_id} failed: reason unknown.')
489
494
 
495
+ def add_cover(self, book_id, filepath, file_ext=None):
496
+ """upload a a cover to a book on the cloud
497
+
498
+ :book_id: id of the book on the serveer
499
+ :filepath: path to the cover file
500
+ :file_ext: png, jpg or jpeg. only necessary if the filepath has no extension
501
+
502
+ """
503
+
504
+ if file_ext is None:
505
+ ext = filepath.split('.')[-1]
506
+
507
+ mime = {
508
+ 'png': 'image/png',
509
+ 'jpeg': 'image/jpeg',
510
+ 'jpg': 'image/jpeg'
511
+ }.get(ext.lower(), 'application/jpeg')
512
+
513
+ host_response = self.session.post(
514
+ self.server_settings['cover_url'],
515
+ files = [('file', ('1092560016', open(filepath, 'rb'), mime))],
516
+ data = {'deliverableId': book_id},
517
+ headers={
518
+ 't_auth_token': self.access_token,
519
+ 'hardware_id': self.hardware_id,
520
+ 'reseller_id': self.server_settings['partner_id'],
521
+ },
522
+ )
523
+
524
+ self._log_requests(host_response)
525
+
526
+ if host_response.status_code != 200:
527
+ raise PytolinoException('cover upload failed.')
528
+
490
529
 
491
530
  if __name__ == '__main__':
492
531
  main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytolino
3
- Version: 1.2
3
+ Version: 1.5
4
4
  Summary: client for tolino cloud
5
5
  Author: Imam Usmani
6
6
  Project-URL: Source Code, https://github.com/ImamAzim/pytolino
@@ -61,6 +61,7 @@ You can then upload, add to a collection or delete ebook on your cloud:
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
63
  client.add_collection(epub_id, 'science fiction') # add the previous book to the collection science-fiction
64
+ client.add_cover(epub_id, cover_path) # to upload a cover on the book.
64
65
  client.delete_ebook(epub_id) # delete the previousely uploaded ebook
65
66
  inventory = client.get_inventory() # get a list of all the books on the cloud and their metadata
66
67
  client.upload_metadata(epub_id, title='my title', author='someone') # you can upload various kind of metadata
@@ -77,6 +78,22 @@ if you want to unregister your computer:
77
78
  client.register() # now you will not be able to upload books from this computer
78
79
  client.logout()
79
80
 
81
+ By default, it will connect to 'www.buecher.de'. In principle you could change the partner with:
82
+
83
+ .. code-block:: python
84
+
85
+ client = Client(server_name='www.orelfuessli') # for example if you have an account at orel fuessli.
86
+
87
+ To get a list of the supported partners:
88
+
89
+ .. code-block:: python
90
+
91
+ from pytolino.tolino_cloud import PARTNERS
92
+ print(PARTNERS)
93
+
94
+ Unfortunately, the only supported partner now is 'www.buecher.de', because it has a different way of connection... So for now, the only solution is to create an account there and link it to your original account.
95
+
96
+
80
97
 
81
98
  Features
82
99
  ========
@@ -9,12 +9,14 @@ import os
9
9
  import unittest
10
10
  import configparser
11
11
  import logging
12
+ import time
13
+ import logging
12
14
 
13
15
 
14
16
  from pytolino.tolino_cloud import Client, PytolinoException
15
17
 
16
18
 
17
- logging.basicConfig(level=logging.INFO)
19
+ # logging.basicConfig(level=logging.INFO)
18
20
 
19
21
 
20
22
  class TestClient(unittest.TestCase):
@@ -130,11 +132,12 @@ def upload_test():
130
132
  username, password = get_credentials()
131
133
  client = Client()
132
134
  client.login(username, password)
135
+ client.register()
133
136
  ebook_id = client.upload(EPUB_PATH)
134
137
  print(ebook_id)
135
138
  with open(EPUB_ID_PATH, 'w') as myfile:
136
139
  myfile.write(ebook_id)
137
-
140
+ client.unregister()
138
141
  client.logout()
139
142
 
140
143
  def collection_test():
@@ -165,12 +168,15 @@ def inventory_test():
165
168
  username, password = get_credentials()
166
169
  client = Client()
167
170
  client.login(username, password)
171
+ client.register()
168
172
  inventory = client.get_inventory()
173
+ client.unregister()
169
174
  client.logout()
170
175
  print(inventory[0].keys())
171
176
  for item in inventory:
172
177
  metadata = item['epubMetaData']
173
- print(metadata.keys())
178
+ print(metadata['title'])
179
+ # print(metadata.keys())
174
180
 
175
181
 
176
182
  def delete_test():
@@ -186,24 +192,58 @@ def delete_test():
186
192
 
187
193
 
188
194
  def metadata_test():
189
- new_metadata = dict(publisher='someone')
195
+
196
+ metadata = dict(
197
+ title='mytitle',
198
+ isbn='myisbn',
199
+ language='mylanguage',
200
+ author='myauthor',
201
+ publisher='mypublisher',
202
+ issued=time.time(),
203
+ )
190
204
  with open(EPUB_ID_PATH, 'r') as myfile:
191
205
  epub_id = myfile.read()
192
206
 
193
207
  username, password = get_credentials()
194
208
  client = Client()
195
209
  client.login(username, password)
196
- client.upload_metadata(epub_id, **new_metadata)
210
+ client.register()
211
+
212
+ client.upload_metadata(epub_id, **metadata)
213
+
197
214
  inventory = client.get_inventory()
198
- for item in inventory:
199
- item_metadata = item['epubMetaData']
200
- if item_metadata['identifier'] == epub_id:
201
- for key, value in new_metadata.items():
202
- print(item_metadata[key])
215
+ book = [el for el in inventory if el['epubMetaData']['identifier']==epub_id][0]
216
+ online_metadata = book['epubMetaData']
217
+ for key in metadata:
218
+ print(key, online_metadata[key])
219
+
220
+ client.unregister()
221
+ client.logout()
222
+
223
+ def add_cover_test():
224
+
225
+ cover_path = os.path.join(
226
+ os.path.expanduser('~'),
227
+ 'cover.jpg',
228
+ )
229
+
230
+ with open(EPUB_ID_PATH, 'r') as myfile:
231
+ epub_id = myfile.read()
232
+
233
+ username, password = get_credentials()
234
+ client = Client()
235
+ client.login(username, password)
236
+ client.add_cover(epub_id, cover_path)
203
237
  client.logout()
204
238
 
205
239
 
206
240
  if __name__ == '__main__':
241
+ # logging.basicConfig(level=logging.INFO)
242
+ # register_test()
243
+ # unregister_test()
244
+ # client_method_tests()
207
245
  # upload_test()
208
- metadata_test()
209
- # inventory_test()
246
+ # delete_test()
247
+ # add_cover_test()
248
+ # metadata_test()
249
+ inventory_test()
File without changes
File without changes
File without changes
File without changes