MCPcopy Index your code
hub / github.com/CL-lau/SQL-GPT / crawl_file

Method crawl_file

model/data_connection.py:87–104  ·  view source on GitHub ↗
(url: str)

Source from the content-addressed store, hash-verified

85
86 @staticmethod
87 def crawl_file(url: str) -> str:
88 try:
89 response = requests.get(url)
90 filetype = os.path.splitext(url)[1]
91 if response.status_code == 200 and (
92 any(ext in filetype for ext in ['.pdf', '.docx', '.csv', '.txt'])
93 ):
94 if response.content.strip():
95 upload_file_name = url.split("/")[-1]
96 file_path = os.path.join("uploads", upload_file_name)
97 with open(file_path, "wb") as f:
98 f.write(response.content)
99 st.success(f"已保存文件: {upload_file_name}")
100 return response.content, filetype
101 else:
102 st.warning('Url cannot parse correctly.')
103 except:
104 st.warning('Url cannot parse correctly.')

Callers 1

Calls 2

getMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected