Skip to content

Commit 89ed1ec

Browse files
committed
fix: fixed design bottleneck for multiple api calls for POTD's hints
1 parent e7836d1 commit 89ed1ec

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/core_logic.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ def run_check():
4646
return
4747

4848
# Get one AI quote for everyone for this run
49-
with Halo(text='Fetching quote from gemini...', spinner='earth', color='cyan') as spinner:
49+
with Halo(text='Fetching quote from gemini...', spinner='balloon2', color='cyan') as spinner:
5050
try:
5151
ai_quote = gemini_service.get_motivational_quote()
5252
spinner.succeed('Quote fetched successfully!')
5353
except Exception as e:
5454
spinner.fail(f'Failed to get motivational quote: {e}')
55-
55+
56+
ai_hints = []
5657

5758
for user in users:
5859
username, email = user["username"], user["email"]
@@ -68,7 +69,6 @@ def run_check():
6869
for sub in submissions
6970
)
7071

71-
ai_hints = []
7272

7373
if solved_today:
7474
print(f"[ {username} ] has already solved the daily problem.")
@@ -77,15 +77,20 @@ def run_check():
7777
print(f" [ {username} ] has not solved the daily problem yet sending reminder...")
7878
subject = f"⏳ Reminder: Solve Today’s LeetCode Problem!"
7979

80-
hint_count = get_hint_count(q_details['difficulty'], q_details['acRate'])
81-
print(f"Difficulty: {q_details['difficulty']}, AC Rate: {format(float(q_details['acRate']), '.2f')}% -> Generating {hint_count} hints.")
82-
83-
with Halo(text='Calling Gemini...', spinner='arrow3', color='blue') as spinner:
84-
ai_hints = gemini_service.generate_optimal_hints(q_details, hint_count)
85-
spinner.succeed('Hints generated successfully!')
8680

81+
print(f"Difficulty: {q_details['difficulty']}, AC Rate: {format(float(q_details['acRate']), '.2f')}% ")
8782

88-
# Send email
83+
if len(ai_hints) == 0:
84+
hint_count = get_hint_count(q_details['difficulty'], q_details['acRate'])
85+
with Halo(text='Generating Hints...', spinner='arrow3', color='blue') as spinner:
86+
try:
87+
ai_hints = gemini_service.generate_optimal_hints(q_details, hint_count)
88+
spinner.succeed('Hints generated successfully!')
89+
except Exception as e:
90+
spinner.fail(f'Failed to generate hints: {e}')
91+
ai_hints = gemini_service.DEFAULT_HINTS
92+
93+
8994
html = email_service.build_html_email(
9095
username=username,
9196
title=q_details['title'],

0 commit comments

Comments
 (0)