Skip to content

Commit

Permalink
Added small RTM to Box API
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertSuarez committed Aug 9, 2019
1 parent 1ddabab commit 72165b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

BOX_CONFIG_FILE_PATH = 'data/jwt_config.json'
BOX_RETRIES = 3
BOX_RTM = 3
BOX_FOLDER_ROOT_ID = '0'
BOX_FOLDER_APP_ID = '84132126414'
BOX_LINK_OPEN_ACCESS = 'open'
Expand Down Expand Up @@ -85,6 +86,7 @@
'STR_CLEAN_DICT',
'BOX_CONFIG_FILE_PATH',
'BOX_RETRIES',
'BOX_RTM',
'BOX_FOLDER_ROOT_ID',
'BOX_FOLDER_APP_ID',
'BOX_LINK_OPEN_ACCESS',
Expand Down
8 changes: 8 additions & 0 deletions src/box_sdk.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from boxsdk import JWTAuth
from boxsdk import Client

Expand All @@ -11,6 +13,7 @@ def create_folder(folder_name):
sub_folder = box_client.folder(BOX_FOLDER_ROOT_ID).create_subfolder(folder_name)
return sub_folder.id
except Exception as e:
time.sleep(BOX_RTM)
if i == BOX_RETRIES - 1:
print(f'Error calling Box API creating the folder [{folder_name}] into folder root: {e}')
return None
Expand All @@ -27,6 +30,7 @@ def create_shared_link(folder_id):
)
return shared_link
except Exception as e:
time.sleep(BOX_RTM)
if i == BOX_RETRIES - 1:
print(f'Error calling Box API creating a shared link for folder [{folder_id}]: {e}')
return None
Expand All @@ -41,6 +45,7 @@ def search_file(folder_id, file_name):
return result.id
return None
except Exception as e:
time.sleep(BOX_RTM)
if i == BOX_RETRIES - 1:
print(f'Error calling Box API searching files into folder [{folder_id}] with name [{file_name}]: {e}')
return None
Expand All @@ -53,6 +58,7 @@ def upload_file(folder_id, file_path):
file_name = file_path.split('/')[-1]
return box_client.folder(folder_id).upload(file_path, file_name).id
except Exception as e:
time.sleep(BOX_RTM)
if i == BOX_RETRIES - 1:
print(f'Error calling Box API uploading the file [{file_path}] to folder with id [{folder_id}]: {e}')
return None
Expand All @@ -64,6 +70,7 @@ def update_file(file_id, file_path):
try:
return box_client.file(file_id).update_contents(file_path).id
except Exception as e:
time.sleep(BOX_RTM)
if i == BOX_RETRIES - 1:
print(f'Error calling Box API updating the file [{file_id}] with file [{file_path}]: {e}')
return None
Expand All @@ -77,6 +84,7 @@ def download_file(file_id, file_path):
box_client.file(file_id).download_to(file)
return True
except Exception as e:
time.sleep(BOX_RTM)
if i == BOX_RETRIES - 1:
print(f'Error calling Box API downloading the file [{file_id}] to file [{file_path}]: {e}')
return None

0 comments on commit 72165b8

Please sign in to comment.