Drag
commited on
Commit
·
f8ea3ca
1
Parent(s):
ee6062f
Update search.py
Browse files- Mikobot/plugins/search.py +17 -5
Mikobot/plugins/search.py
CHANGED
@@ -36,14 +36,23 @@ API_CONFIG = {
|
|
36 |
|
37 |
@app.on_message(filters.command("news"))
|
38 |
async def news(_, message: Message):
|
39 |
-
keyword = (
|
40 |
-
message.text.split(" ", 1)[1].strip() if len(message.text.split()) > 1 else ""
|
41 |
-
)
|
42 |
api_url = API_CONFIG["news_api"]["url"].format(keyword, api_key=API_CONFIG["news_api"]["api_key"])
|
43 |
|
44 |
try:
|
|
|
|
|
|
|
|
|
45 |
response = await state.get(api_url)
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
news_data = response.json()
|
|
|
47 |
|
48 |
if news_data.get("status") == "ok":
|
49 |
articles = news_data.get("articles", [])
|
@@ -60,9 +69,12 @@ async def news(_, message: Message):
|
|
60 |
else:
|
61 |
await message.reply_text("No news found.")
|
62 |
else:
|
63 |
-
await message.reply_text(f"Error: {news_data.get('message', 'Unknown error')}")
|
64 |
except Exception as e:
|
65 |
-
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
@app.on_message(filters.command("bingsearch"))
|
|
|
36 |
|
37 |
@app.on_message(filters.command("news"))
|
38 |
async def news(_, message: Message):
|
39 |
+
keyword = message.text.split(" ", 1)[1].strip() if len(message.text.split()) > 1 else ""
|
|
|
|
|
40 |
api_url = API_CONFIG["news_api"]["url"].format(keyword, api_key=API_CONFIG["news_api"]["api_key"])
|
41 |
|
42 |
try:
|
43 |
+
# Log the constructed URL (for debugging)
|
44 |
+
print(f"Requesting URL: {api_url}")
|
45 |
+
|
46 |
+
# Send the request to the API
|
47 |
response = await state.get(api_url)
|
48 |
+
print(f"Response Status Code: {response.status_code}") # Log status code
|
49 |
+
|
50 |
+
if response.status_code != 200:
|
51 |
+
await message.reply_text(f"API Error: {response.status_code}")
|
52 |
+
return
|
53 |
+
|
54 |
news_data = response.json()
|
55 |
+
print(f"Response JSON: {news_data}") # Log the JSON response
|
56 |
|
57 |
if news_data.get("status") == "ok":
|
58 |
articles = news_data.get("articles", [])
|
|
|
69 |
else:
|
70 |
await message.reply_text("No news found.")
|
71 |
else:
|
72 |
+
await message.reply_text(f"API Response Error: {news_data.get('message', 'Unknown error')}")
|
73 |
except Exception as e:
|
74 |
+
# Log the error for debugging
|
75 |
+
print(f"Exception occurred: {e}")
|
76 |
+
await message.reply_text(f"An error occurred: {str(e)}")
|
77 |
+
|
78 |
|
79 |
|
80 |
@app.on_message(filters.command("bingsearch"))
|