Update tsadropboxretrieval.py
Browse files- tsadropboxretrieval.py +25 -2
tsadropboxretrieval.py
CHANGED
|
@@ -133,14 +133,37 @@ def uploadmarkupPDFTable(doc,pdfname,path):
|
|
| 133 |
except Exception as e:
|
| 134 |
print('Error uploading file to Dropbox: ' + str(e))
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
def uploadanyFile(doc,pdfname,path,flag=0):
|
| 137 |
try:
|
| 138 |
dbxTeam= ADR_Access_DropboxTeam('admin')
|
| 139 |
-
print('ppp')
|
| 140 |
if flag: #tree = doc
|
| 141 |
pdfname=str(pdfname).split('.pdf')[0]+'.xml'
|
| 142 |
path=path+pdfname
|
| 143 |
-
print(path)
|
| 144 |
f = BytesIO()
|
| 145 |
doc.write(f, encoding='utf-8', xml_declaration=True)
|
| 146 |
exists_bool=check_if_file_exists(dbxTeam,path)
|
|
|
|
| 133 |
except Exception as e:
|
| 134 |
print('Error uploading file to Dropbox: ' + str(e))
|
| 135 |
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def upload_string_file(content_str, filename, path):
|
| 139 |
+
try:
|
| 140 |
+
dbxTeam = ADR_Access_DropboxTeam('admin')
|
| 141 |
+
full_path = path + filename
|
| 142 |
+
# convert string to bytes
|
| 143 |
+
f = BytesIO(content_str.encode("utf-8"))
|
| 144 |
+
# delete if file already exists
|
| 145 |
+
if check_if_file_exists(dbxTeam, full_path):
|
| 146 |
+
dbxTeam.files_delete(full_path)
|
| 147 |
+
# upload
|
| 148 |
+
meta = dbxTeam.files_upload(f.getvalue(), full_path)
|
| 149 |
+
# create shared link
|
| 150 |
+
try:
|
| 151 |
+
shared_link_metadata = dbxTeam.sharing_create_shared_link_with_settings(full_path)
|
| 152 |
+
except:
|
| 153 |
+
shared_link_metadata = dbxTeam.sharing_create_shared_link(full_path)
|
| 154 |
+
return shared_link_metadata.url
|
| 155 |
+
except Exception as e:
|
| 156 |
+
print("Error uploading file to Dropbox:", str(e))
|
| 157 |
+
return "Error uploading file to Dropbox."
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
|
| 161 |
def uploadanyFile(doc,pdfname,path,flag=0):
|
| 162 |
try:
|
| 163 |
dbxTeam= ADR_Access_DropboxTeam('admin')
|
|
|
|
| 164 |
if flag: #tree = doc
|
| 165 |
pdfname=str(pdfname).split('.pdf')[0]+'.xml'
|
| 166 |
path=path+pdfname
|
|
|
|
| 167 |
f = BytesIO()
|
| 168 |
doc.write(f, encoding='utf-8', xml_declaration=True)
|
| 169 |
exists_bool=check_if_file_exists(dbxTeam,path)
|