-
Notifications
You must be signed in to change notification settings - Fork 1
/
birthday_wisher.py
39 lines (29 loc) · 1002 Bytes
/
birthday_wisher.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
import os
import aiohttp
from discord import Webhook, AsyncWebhookAdapter
from dotenv import load_dotenv
import asyncio
import random
import platform
from readfile import check_bday
load_dotenv()
WEBHOOK_URL = os.getenv("DISCORD_WEBHOOK")
wish_file = open("wishes.txt", "r")
wish_list = wish_file.read().split('\n')
birthday_peeps = check_bday()
def birthday_message(name):
return f"""
@everyone Wish {name} a very Happy Birthday 🥳
🎉 Hey {name},
🎂 {random.choice(wish_list)} 🎁
"""
# configuring asyncio for windows
if platform.system()=='Windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
async def wisher(msg):
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(WEBHOOK_URL, adapter=AsyncWebhookAdapter(session))
await webhook.send(msg, username='CSI Birthday Wisher')
async def runner():
for name in birthday_peeps : await wisher(birthday_message(name))
# asyncio.run(main())