adragos commited on
Commit
6c226fa
·
1 Parent(s): 088bcef

Implement hard challenge chunking

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -186,7 +186,6 @@ def summary(webhook_url, disable_discord, env, username, state):
186
  if env == Env.PLAYGROUND:
187
  if not disable_discord:
188
  webhook_url = webhook_url or discord_webhook_url_public
189
-
190
  try:
191
  r = requests.post(webhook_url, json={"content": summary, "allowed_mentions": {"parse": []}})
192
  r.raise_for_status()
@@ -195,8 +194,17 @@ def summary(webhook_url, disable_discord, env, username, state):
195
  elif env == Env.CHALLENGE_EASY:
196
  webhook_url = discord_webhook_url_easy
197
  try:
198
- r = requests.post(webhook_url, json={"content": summary, "allowed_mentions": {"parse": []}})
199
- r.raise_for_status()
 
 
 
 
 
 
 
 
 
200
  except Exception:
201
  return "Error: webhook discord failed"
202
  elif env == Env.CHALLENGE_HARD:
@@ -288,13 +296,25 @@ def run_summary_hard():
288
  rows.insert(random.randint(0, len(rows)), new_row)
289
 
290
  summary = get_summary(rows)
291
- print("summary: ", summary)
 
292
 
293
  db.close()
294
 
295
  try:
296
- r = requests.post(discord_webhook_url_hard, json={"content": summary, "allowed_mentions": {"parse": []}})
297
- r.raise_for_status()
 
 
 
 
 
 
 
 
 
 
 
298
  except Exception:
299
  return "Error: webhook discord failed"
300
 
 
186
  if env == Env.PLAYGROUND:
187
  if not disable_discord:
188
  webhook_url = webhook_url or discord_webhook_url_public
 
189
  try:
190
  r = requests.post(webhook_url, json={"content": summary, "allowed_mentions": {"parse": []}})
191
  r.raise_for_status()
 
194
  elif env == Env.CHALLENGE_EASY:
195
  webhook_url = discord_webhook_url_easy
196
  try:
197
+ chunk = ""
198
+ for word in summary.split(' '):
199
+ if len(word) + 1 + len(chunk) < 2000:
200
+ chunk += word + " "
201
+ else:
202
+ r = requests.post(discord_webhook_url_hard, json={"content": chunk, "allowed_mentions": {"parse": []}})
203
+ r.raise_for_status()
204
+ chunk = ""
205
+ if chunk:
206
+ r = requests.post(discord_webhook_url_hard, json={"content": chunk, "allowed_mentions": {"parse": []}})
207
+ r.raise_for_status()
208
  except Exception:
209
  return "Error: webhook discord failed"
210
  elif env == Env.CHALLENGE_HARD:
 
296
  rows.insert(random.randint(0, len(rows)), new_row)
297
 
298
  summary = get_summary(rows)
299
+ print("hard summary: ", summary)
300
+ print("end hard summary")
301
 
302
  db.close()
303
 
304
  try:
305
+ chunk = ""
306
+ for word in summary.split(' '):
307
+ if len(word) + 1 + len(chunk) < 2000:
308
+ chunk += word + " "
309
+ else:
310
+ r = requests.post(discord_webhook_url_hard, json={"content": chunk, "allowed_mentions": {"parse": []}})
311
+ r.raise_for_status()
312
+ print("hard chall chunk: ", chunk)
313
+ chunk = ""
314
+ if chunk:
315
+ print("hard chall chunk: ", chunk)
316
+ r = requests.post(discord_webhook_url_hard, json={"content": chunk, "allowed_mentions": {"parse": []}})
317
+ r.raise_for_status()
318
  except Exception:
319
  return "Error: webhook discord failed"
320