Update app.py
Browse filesfixed missing indent
app.py
CHANGED
|
@@ -77,29 +77,29 @@ class FetchFileTool(Tool):
|
|
| 77 |
},
|
| 78 |
}
|
| 79 |
output_type = "boolean"
|
| 80 |
-
|
| 81 |
-
def forward(self, location: str, file_path: str, file_name: str):
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
full_path = os.path.join(file_path, file_name)
|
| 87 |
-
with open(full_path, 'wb') as out_file:
|
| 88 |
-
out_file.write(content)
|
| 89 |
-
return True
|
| 90 |
-
|
| 91 |
-
except Exception as e:
|
| 92 |
-
# if error is HTTP 429 then copy from /files
|
| 93 |
-
if response.status_code == 429:
|
| 94 |
-
# get last part of location separated by slash
|
| 95 |
-
file_id = location.split('/')[-1]
|
| 96 |
-
local_path = f"files/{file_id}"
|
| 97 |
full_path = os.path.join(file_path, file_name)
|
| 98 |
-
|
|
|
|
| 99 |
return True
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
fetch_file_tool = FetchFileTool()
|
| 105 |
|
|
|
|
| 77 |
},
|
| 78 |
}
|
| 79 |
output_type = "boolean"
|
| 80 |
+
|
| 81 |
+
def forward(self, location: str, file_path: str, file_name: str):
|
| 82 |
+
try:
|
| 83 |
+
response = requests.get(location)
|
| 84 |
+
response.raise_for_status()
|
| 85 |
+
content = response.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
full_path = os.path.join(file_path, file_name)
|
| 87 |
+
with open(full_path, 'wb') as out_file:
|
| 88 |
+
out_file.write(content)
|
| 89 |
return True
|
| 90 |
+
|
| 91 |
+
except Exception as e:
|
| 92 |
+
# if error is HTTP 429 then copy from /files
|
| 93 |
+
if response.status_code == 429:
|
| 94 |
+
# get last part of location separated by slash
|
| 95 |
+
file_id = location.split('/')[-1]
|
| 96 |
+
local_path = f"files/{file_id}"
|
| 97 |
+
full_path = os.path.join(file_path, file_name)
|
| 98 |
+
shutil.copy(local_path, full_path)
|
| 99 |
+
return True
|
| 100 |
+
else:
|
| 101 |
+
print(f"Error saving content to file: {e}")
|
| 102 |
+
return False
|
| 103 |
|
| 104 |
fetch_file_tool = FetchFileTool()
|
| 105 |
|