pytolino 1.4__tar.gz → 1.6__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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: pytolino
3
- Version: 1.4
3
+ Version: 1.6
4
4
  Summary: client for tolino cloud
5
5
  Author: Imam Usmani
6
6
  Project-URL: Source Code, https://github.com/ImamAzim/pytolino
@@ -23,6 +23,7 @@ Requires-Dist: sphinx; extra == "dev"
23
23
  Requires-Dist: build; extra == "dev"
24
24
  Requires-Dist: twine; extra == "dev"
25
25
  Requires-Dist: sphinx-rtd-theme; extra == "dev"
26
+ Dynamic: license-file
26
27
 
27
28
  pytolino
28
29
  ===================
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pytolino"
7
- version = "1.4"
7
+ version = "1.6"
8
8
  authors = [
9
9
  {name="Imam Usmani"},
10
10
  ]
@@ -6,11 +6,13 @@ import configparser
6
6
  import platform
7
7
  import logging
8
8
  from urllib.parse import urlparse, parse_qs
9
+ from urllib3.util import Retry
9
10
  import json
10
11
  import time
11
12
 
12
13
 
13
14
  import requests
15
+ from requests.adapters import HTTPAdapter
14
16
  import mechanize
15
17
 
16
18
 
@@ -27,6 +29,8 @@ servers_settings = configparser.ConfigParser()
27
29
  servers_settings.read(SERVERS_SETTINGS_FILE_PATH)
28
30
 
29
31
  PARTNERS = servers_settings.sections()
32
+ TOTAL_RETRY =5
33
+ STATUS_FORCELIST = [404]
30
34
 
31
35
 
32
36
  def main():
@@ -124,8 +128,17 @@ class Client(object):
124
128
  self.token_expires = None
125
129
 
126
130
  self.server_settings = servers_settings[server_name]
127
- self.session = requests.session()
131
+ self.session = requests.Session()
132
+ retry_strategy = Retry(
133
+ total=TOTAL_RETRY,
134
+ status_forcelist=STATUS_FORCELIST,
135
+ backoff_factor=2,
136
+ allowed_methods=frozenset(['GET', 'POST']))
137
+ adapter = HTTPAdapter(max_retries=retry_strategy)
138
+ self.session.mount('http://', adapter)
139
+ self.session.mount('https://', adapter)
128
140
  self.browser = mechanize.Browser()
141
+ self.browser.set_handle_robots(False)
129
142
  self.server_name = server_name
130
143
 
131
144
  def login(self, username, password):
@@ -195,6 +208,7 @@ class Client(object):
195
208
  allow_redirects=False,
196
209
  )
197
210
  self._log_requests(host_response)
211
+
198
212
  try:
199
213
  j = host_response.json()
200
214
  self.access_token = j['access_token']
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: pytolino
3
- Version: 1.4
3
+ Version: 1.6
4
4
  Summary: client for tolino cloud
5
5
  Author: Imam Usmani
6
6
  Project-URL: Source Code, https://github.com/ImamAzim/pytolino
@@ -23,6 +23,7 @@ Requires-Dist: sphinx; extra == "dev"
23
23
  Requires-Dist: build; extra == "dev"
24
24
  Requires-Dist: twine; extra == "dev"
25
25
  Requires-Dist: sphinx-rtd-theme; extra == "dev"
26
+ Dynamic: license-file
26
27
 
27
28
  pytolino
28
29
  ===================
@@ -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,20 +192,32 @@ 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()
203
221
  client.logout()
204
222
 
205
223
  def add_cover_test():
@@ -220,7 +238,12 @@ def add_cover_test():
220
238
 
221
239
 
222
240
  if __name__ == '__main__':
241
+ logging.basicConfig(level=logging.INFO)
242
+ # register_test()
243
+ # unregister_test()
244
+ client_method_tests()
223
245
  # upload_test()
224
- add_cover_test()
246
+ # delete_test()
247
+ # add_cover_test()
225
248
  # metadata_test()
226
249
  # inventory_test()
File without changes
File without changes
File without changes
File without changes
File without changes