Skip to content

Commit 32abf39

Browse files
committed
quick fix for supabase using try except
1 parent 0347c7a commit 32abf39

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

ai_ta_backend/web_scrape.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -323,22 +323,28 @@ def main_crawler(url:str, course_name:str, max_urls:int=100, max_depth:int=3, ti
323323
del ingester
324324
return results
325325
else:
326-
print("Gathering existing urls from Supabase")
327-
supabase_client = supabase.create_client( # type: ignore
328-
supabase_url=os.getenv('SUPABASE_URL'), # type: ignore
329-
supabase_key=os.getenv('SUPABASE_API_KEY')) # type: ignore
330-
urls = supabase_client.table(os.getenv('NEW_NEW_NEWNEW_MATERIALS_SUPABASE_TABLE')).select('course_name, url, contexts').eq('course_name', course_name).execute()
331-
del supabase_client
332-
if urls.data == []:
326+
try:
327+
print("Gathering existing urls from Supabase")
328+
supabase_client = supabase.create_client( # type: ignore
329+
supabase_url=os.getenv('SUPABASE_URL'), # type: ignore
330+
supabase_key=os.getenv('SUPABASE_API_KEY')) # type: ignore
331+
urls = supabase_client.table(os.getenv('NEW_NEW_NEWNEW_MATERIALS_SUPABASE_TABLE')).select('course_name, url, contexts').eq('course_name', course_name).execute()
332+
del supabase_client
333+
if urls.data == []:
334+
existing_urls = None
335+
else:
336+
existing_urls = []
337+
for thing in urls.data:
338+
whole = ''
339+
for t in thing['contexts']:
340+
whole += t['text']
341+
existing_urls.append((thing['url'], whole))
342+
print("Finished gathering existing urls from Supabase")
343+
except Exception as e:
344+
print("Error:", e)
345+
print("Could not gather existing urls from Supabase")
333346
existing_urls = None
334-
else:
335-
existing_urls = []
336-
for thing in urls.data:
337-
whole = ''
338-
for t in thing['contexts']:
339-
whole += t['text']
340-
existing_urls.append((thing['url'], whole))
341-
print("Finished gathering existing urls from Supabase")
347+
342348
print("Begin Ingesting Web page")
343349
data = crawler(url=url, max_urls=max_urls, max_depth=max_depth, timeout=timeout, base_url_on=stay_on_baseurl, _existing_urls=existing_urls)
344350

0 commit comments

Comments
 (0)