Spaces:
Sleeping
Sleeping
Update tsadropboxretrieval.py
Browse files- tsadropboxretrieval.py +18 -3
tsadropboxretrieval.py
CHANGED
|
@@ -101,24 +101,40 @@ def dropbox_upload_file(df, flag=0):
|
|
| 101 |
print('Error uploading file to Dropbox: ' + str(e))
|
| 102 |
return dbxTeam
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
def uploadanyFile(doc,pdfname,path,flag=0):
|
| 106 |
try:
|
| 107 |
dbxTeam= ADR_Access_DropboxTeam('admin')
|
|
|
|
| 108 |
if flag: #tree = doc
|
| 109 |
pdfname=str(pdfname).split('.pdf')[0]+'.xml'
|
| 110 |
path=path+pdfname
|
|
|
|
| 111 |
f = BytesIO()
|
| 112 |
doc.write(f, encoding='utf-8', xml_declaration=True)
|
| 113 |
-
dbxTeam
|
|
|
|
|
|
|
| 114 |
meta=dbxTeam.files_upload(f.getvalue() ,path)
|
| 115 |
else:
|
| 116 |
path=path+pdfname
|
| 117 |
-
dbxTeam
|
|
|
|
|
|
|
| 118 |
meta=dbxTeam.files_upload(doc.write() ,path)
|
| 119 |
try:
|
|
|
|
| 120 |
shared_link_metadata = dbxTeam.sharing_create_shared_link_with_settings(path)
|
| 121 |
except:
|
|
|
|
| 122 |
shared_link_metadata=dbxTeam.sharing_create_shared_link(path)
|
| 123 |
return shared_link_metadata.url
|
| 124 |
except Exception as e:
|
|
@@ -206,7 +222,6 @@ def retrieveProjects(projname):
|
|
| 206 |
|
| 207 |
# Remove the temporary 'path_display_lower' column
|
| 208 |
parquetDf.drop(columns=['path_display_lower'], inplace=True)
|
| 209 |
-
print('done')
|
| 210 |
return documentsToMeasure,RelevantDocuments
|
| 211 |
|
| 212 |
|
|
|
|
| 101 |
print('Error uploading file to Dropbox: ' + str(e))
|
| 102 |
return dbxTeam
|
| 103 |
|
| 104 |
+
def check_if_file_exists(dbxTeam,path):
|
| 105 |
+
try:
|
| 106 |
+
md = dbxTeam.files_get_metadata(path)
|
| 107 |
+
exists_bool = True
|
| 108 |
+
return exists_bool
|
| 109 |
+
except Exception as error_response:
|
| 110 |
+
exists_bool = False
|
| 111 |
+
return exists_bool
|
| 112 |
|
| 113 |
def uploadanyFile(doc,pdfname,path,flag=0):
|
| 114 |
try:
|
| 115 |
dbxTeam= ADR_Access_DropboxTeam('admin')
|
| 116 |
+
print('ppp')
|
| 117 |
if flag: #tree = doc
|
| 118 |
pdfname=str(pdfname).split('.pdf')[0]+'.xml'
|
| 119 |
path=path+pdfname
|
| 120 |
+
print(path)
|
| 121 |
f = BytesIO()
|
| 122 |
doc.write(f, encoding='utf-8', xml_declaration=True)
|
| 123 |
+
exists_bool=check_if_file_exists(dbxTeam,path)
|
| 124 |
+
if exists_bool:
|
| 125 |
+
dbxTeam.files_delete(path)
|
| 126 |
meta=dbxTeam.files_upload(f.getvalue() ,path)
|
| 127 |
else:
|
| 128 |
path=path+pdfname
|
| 129 |
+
exists_bool=check_if_file_exists(dbxTeam,path)
|
| 130 |
+
if exists_bool:
|
| 131 |
+
dbxTeam.files_delete(path)
|
| 132 |
meta=dbxTeam.files_upload(doc.write() ,path)
|
| 133 |
try:
|
| 134 |
+
print('hereintry')
|
| 135 |
shared_link_metadata = dbxTeam.sharing_create_shared_link_with_settings(path)
|
| 136 |
except:
|
| 137 |
+
print('hereinexcept')
|
| 138 |
shared_link_metadata=dbxTeam.sharing_create_shared_link(path)
|
| 139 |
return shared_link_metadata.url
|
| 140 |
except Exception as e:
|
|
|
|
| 222 |
|
| 223 |
# Remove the temporary 'path_display_lower' column
|
| 224 |
parquetDf.drop(columns=['path_display_lower'], inplace=True)
|
|
|
|
| 225 |
return documentsToMeasure,RelevantDocuments
|
| 226 |
|
| 227 |
|