Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
f2e3f46
1
Parent(s): fc6d7ac
test 6
Browse files
logger.py
CHANGED
|
@@ -1,43 +1,27 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
import datetime
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Get system uptime
|
| 11 |
-
boot_time = datetime.fromtimestamp(psutil.boot_time())
|
| 12 |
-
current_time = datetime.now()
|
| 13 |
-
uptime_delta = current_time - boot_time
|
| 14 |
-
uptime_seconds = uptime_delta.total_seconds()
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
uptime_hours, remainder = divmod(remainder, 3600)
|
| 19 |
-
uptime_minutes, uptime_seconds = divmod(remainder, 60)
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
"days": int(uptime_days),
|
| 36 |
-
"hours": int(uptime_hours),
|
| 37 |
-
"minutes": int(uptime_minutes),
|
| 38 |
-
"seconds": int(uptime_seconds)
|
| 39 |
-
},
|
| 40 |
-
"CPU Usage": f"{cpu_percent}%",
|
| 41 |
-
"Memory Usage": f"{memory_percent}%",
|
| 42 |
-
"Latency to Google": f"{latency_ms} ms"
|
| 43 |
-
}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
import discord
|
| 3 |
+
import os
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
+
# Initialize a Discord client
|
| 8 |
+
client = discord.Client()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Discord bot token
|
| 11 |
+
BOT_TOKEN = os.getenv('DISCORD_TOKEN')
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Event to handle when the bot is ready
|
| 14 |
+
@client.event
|
| 15 |
+
async def on_ready():
|
| 16 |
+
print(f'We have logged in as {client.user}')
|
| 17 |
|
| 18 |
+
# Endpoint to get the status of the Discord bot
|
| 19 |
+
@app.get("/")
|
| 20 |
+
async def get_bot_status():
|
| 21 |
+
if client.is_ready():
|
| 22 |
+
return {"status": "Online"}
|
| 23 |
+
else:
|
| 24 |
+
return {"status": "Offline"}
|
| 25 |
|
| 26 |
+
# Start the Discord bot
|
| 27 |
+
client.run(BOT_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|