Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

issue #45 use cloudscraper for requests #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__
*.bak
*.un~
2 changes: 1 addition & 1 deletion tolinoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def upload(args):
c.register()
document_id = c.upload(args.filename, args.name)
c.unregister()
c.logout()
# c.logout()
print('uploaded {} to tolino cloud as {}.'.format(args.filename, document_id))

def download(args):
Expand Down
25 changes: 13 additions & 12 deletions tolinocloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.


import cloudscraper
import platform
import json
import base64
Expand Down Expand Up @@ -129,6 +129,7 @@ def _hardware_id():
'x_buchde.mandant_id' :'2',
'auth_url' : 'https://www.thalia.de/de.thalia.ecp.authservice.application/oauth2/authorize',
'login_url' : 'https://www.thalia.de/de.thalia.ecp.authservice.application/login.do',
'revoke_url' : 'https://www.thalia.de/auth/oauth2/revoke',
# 'revoke_url' : 'https://www.thalia.de/de.buch.appservices/api/2004/oauth2/revoke',
'login_form' : {
'username' : 'j_username',
Expand Down Expand Up @@ -282,7 +283,7 @@ def _debug(self, r):
logging.debug('-------------------------------------------------------')

def login(self, username, password):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

# Login with partner site
Expand Down Expand Up @@ -352,14 +353,14 @@ def login(self, username, password):
raise TolinoException('oauth access token request failed.')

def logout(self):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

if 'revoke_url' in c:
r = s.post(c['revoke_url'],
data = {
'client_id' : c['client_id'],
'token_type' : 'refresh_token',
'token_type_hint' : 'refresh_token',
'token' : self.refresh_token
}
)
Expand All @@ -374,7 +375,7 @@ def logout(self):


def register(self):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

# Register our hardware
Expand All @@ -395,7 +396,7 @@ def register(self):
raise TolinoException('register {} failed.'.format(TolinoCloud.hardware_id))

def unregister(self, device_id = hardware_id):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

r = s.post(c['unregister_url'],
Expand Down Expand Up @@ -426,7 +427,7 @@ def unregister(self, device_id = hardware_id):
raise TolinoException('unregister {} failed: reason unknown.'.format(device_id))

def devices(self):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

r = s.post(c['devices_url'],
Expand Down Expand Up @@ -487,7 +488,7 @@ def _parse_metadata(self, j):
raise TolinoException('could not parse metadata')

def inventory(self):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

r = s.get(c['inventory_url'],
Expand Down Expand Up @@ -516,7 +517,7 @@ def inventory(self):
raise TolinoException('inventory list request failed.')

def upload(self, filename, name = None, ext = None):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

if name is None:
Expand Down Expand Up @@ -548,7 +549,7 @@ def upload(self, filename, name = None, ext = None):
raise TolinoException('file upload failed.')

def delete(self, id):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

r = s.get(c['delete_url'],
Expand All @@ -570,7 +571,7 @@ def delete(self, id):
raise TolinoException('delete {} failed: reason unknown.'.format(id))

def download_info(self, id):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

b64 = base64.b64encode(bytes(id, 'utf-8')).decode('utf-8')
Expand All @@ -594,7 +595,7 @@ def download_info(self, id):
}

def download(self, path, id):
s = self.session;
s = cloudscraper.create_scraper(delay=6);
c = self.partner_settings[self.partner_id]

di = self.download_info(id)
Expand Down