-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStatus.py
44 lines (39 loc) · 1.89 KB
/
Status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import discord
import aiohttp
import datetime
import hdate
import json
class Status(discord.ext.commands.Cog):
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession(loop=bot.loop)
self.api_url = "https://www.sefaria.org/api/calendars"
self.change_status.start()
@discord.ext.tasks.loop(hours=1)
async def change_status(self):
async with aiohttp.ClientSession() as session:
async with session.get(self.api_url) as response:
body = await response.text()
sefaria_obj = json.loads(body)
date = hdate.HDate(datetime.datetime.now(), hebrew=False)
status_string = f"""
{date.hebrew_date}
| Today's Parasha: {sefaria_obj["calendar_items"][0]["displayValue"]["en"]}
| Today's Haftarah: {sefaria_obj["calendar_items"][1]["displayValue"]["en"]}
"""
status_string = status_string.replace("\n", " ")
status_string = status_string.replace("\r", " ")
status_string = status_string.replace(" ", "")
if len(status_string) > 128:
status_string = f"""
Today's Parasha: {sefaria_obj["calendar_items"][0]["displayValue"]["en"]}
| Today's Haftarah: {sefaria_obj["calendar_items"][1]["displayValue"]["en"]}
"""
status_string = status_string.replace("\n", " ")
status_string = status_string.replace("\r", " ")
status_string = status_string.replace(" ", "")
print(f"The status string is {len(status_string)} chars")
game = discord.Game(status_string)
await self.bot.change_presence(status=discord.Status.online, activity=game)
async def setup(bot):
await bot.add_cog(Status(bot))