Skip to content

Commit f25471f

Browse files
authored
Remove unnecessary try catch blocks in fetch announcement task
1 parent fd02be2 commit f25471f

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

core/tasks.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -346,32 +346,26 @@ def fetch_announcements():
346346

347347
prompt = f"You are a meticulous and organized secretary at a Canadian high school. Your job is to accurately assign titles to announcements and figure out which club that announcement belongs to. Accuracy and consistency are paramount. The titles should be no more than 64 characters long. It should be descriptive of the announcement itself. Do not go over the limit. You will be provided an array of announcements. Each element in the array will contain the data for one announcement. The element will be in the format of a json object containing the body (what will be announced out) and the club_name (students may mistype clubs names, etc so you will need to pick which one you think they were trying to reference). The available names of all the clubs of the school will be provided below to you in the format of an array (E.g. ['club name 1', 'club name 2', 'club name 3', ... ]). \nWhen outputting, output a single array object. The array order must match the order of the one provided to you. DO NOT CHANGE THE ORDER UNDER ANY CIRCUMSTANCE. The array format should be the same as announcements array given to you. Each element are to be a json object, one key will be the title and the other will be the club name. Should no club match the one the student was trying to pick, then and ONLY then will you put down the club name they have listed. In this scenario, please output it in pascal case and remove any unnecessary information that is not relating to the club name itself. For example, if it's written as 'CLUB NAME (OTHER INFORMATION)', it should be outputted as just 'Club Name'. If you do find a club name in the club name array that matches the one the student was trying to write, it should be EXACTLY the same during output. Do not output anything besides the array.\nClub names: {organizations}\nAnnouncements to be titled: {dumps(prompt_data)}"
348348

349-
try:
350-
response = prompt_gemini(prompt, model="models/gemini-2.5-flash")
351-
response = response.text.replace("```json", "").replace("```", "")
352-
response = loads(response)
353-
except Exception:
354-
logger.warning("Fetch Announcement: Something went wrong with the AI")
349+
response = prompt_gemini(prompt, model="models/gemini-2.5-flash")
350+
response = response.text.replace("```json", "").replace("```", "")
351+
response = loads(response)
355352

356-
try:
357-
for index, el in enumerate(response):
358-
data = row_data[index]
353+
for index, el in enumerate(response):
354+
data = row_data[index]
359355

360-
try:
361-
org = Organization.objects.get(name=el["club_name"])
362-
data["organization"] = org
356+
try:
357+
org = Organization.objects.get(name=el["club_name"])
358+
data["organization"] = org
363359

364-
if data["author"] is None:
365-
data["author"] = org.owners.all()[0]
366-
except ObjectDoesNotExist:
367-
data["organization_string"] = el["club_name"]
360+
if data["author"] is None:
361+
data["author"] = org.owners.all()[0]
362+
except ObjectDoesNotExist:
363+
data["organization_string"] = el["club_name"]
368364

369-
data["title"] = el["title"]
370-
del data["club_name"]
365+
data["title"] = el["title"]
366+
del data["club_name"]
371367

372-
Announcement.objects.get_or_create(body=data["body"], defaults=data)
373-
except Exception:
374-
logger.warning("Fetch Announcement: Something went wrong creating the object")
368+
Announcement.objects.get_or_create(body=data["body"], defaults=data)
375369

376370

377371
@app.task

0 commit comments

Comments
 (0)