q6 commited on
Commit
8dc4494
·
1 Parent(s): 66f26e9

load .env and error logging

Browse files
Files changed (1) hide show
  1. backend/app.py +14 -3
backend/app.py CHANGED
@@ -3,8 +3,16 @@ import io
3
  import json
4
  import os
5
  import time
 
6
  from urllib.parse import parse_qs, parse_qsl, quote, unquote, urlencode, urlsplit
7
 
 
 
 
 
 
 
 
8
  import aiohttp
9
  import httpx
10
  import numpy as np
@@ -110,12 +118,15 @@ async def init_db():
110
 
111
  async def discord_notify(msg):
112
  if not DISCORD_WEBHOOK_URL:
 
113
  return
114
  try:
115
  async with httpx.AsyncClient(timeout=10) as client:
116
- await client.post(DISCORD_WEBHOOK_URL, json={"content": msg})
117
- except Exception:
118
- pass
 
 
119
 
120
 
121
  def is_ai_post(post):
 
3
  import json
4
  import os
5
  import time
6
+ from pathlib import Path
7
  from urllib.parse import parse_qs, parse_qsl, quote, unquote, urlencode, urlsplit
8
 
9
+ try:
10
+ from dotenv import load_dotenv
11
+
12
+ load_dotenv(Path(__file__).resolve().parent.parent / ".env")
13
+ except ImportError:
14
+ pass
15
+
16
  import aiohttp
17
  import httpx
18
  import numpy as np
 
118
 
119
  async def discord_notify(msg):
120
  if not DISCORD_WEBHOOK_URL:
121
+ print("WARN: DISCORD_WEBHOOK_URL not set, skipping notify")
122
  return
123
  try:
124
  async with httpx.AsyncClient(timeout=10) as client:
125
+ r = await client.post(DISCORD_WEBHOOK_URL, json={"content": msg})
126
+ if r.status_code >= 400:
127
+ print(f"Discord webhook failed ({r.status_code}): {r.text}")
128
+ except Exception as e:
129
+ print(f"Discord webhook error: {e}")
130
 
131
 
132
  def is_ai_post(post):