-
Notifications
You must be signed in to change notification settings - Fork 0
/
reminderbot.py
141 lines (105 loc) · 5.01 KB
/
reminderbot.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from pytz import timezone
from datetime import datetime
from bs4 import BeautifulSoup
import discord
import os
import requests
import time
from asyncio import sleep as s
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
if msg.startswith('.running'):
await message.channel.send('Yes :slight_smile:')
if msg.startswith('.help'):
await message.channel.send('".running" -> to check active or not')
if msg.startswith('.fhdfgjkfjkfyjyxrthhtherhdfetjmudyah'):
# await message.channel.send('Reminder Set')
while (True):
# await message.channel.send('still running')
url = 'https://codeforces.com/contests'
r = requests.get(url)
htmlContent = r.content
soup = BeautifulSoup(htmlContent, 'html.parser')
datatable = soup.find(class_='datatable')
l = list(datatable.stripped_strings)
# l.pop(15)
now = datetime.now(timezone("Asia/Kolkata"))
current_time = now.strftime("%H:%M:%S")
current_time = current_time[3:]
# curdate = now.strftime("%b/%d")
# await message.channel.send(current_time + ' ' + curdate)
# if ((current_time == '32:00') or (current_time == '32:01')):
l = l[5:]
# await message.channel.send('Inside!!')
for i in range(len(l)):
if (l[i] == 'Before start'):
contimeleft = l[i + 1]
# condate = l[i-2][0:6]
# await message.channel.send(contimeleft)
# if(curdate == condate):
if (len(contimeleft) == 8):
# print(contimeleft[0:5])
conname = ''
if (contimeleft[0:2] == '12'):
j = i
while (l[j] != 'Until closing' and j != 0):
j -= 1
if j <= 0:
conname = l[0]
else:
if (l[j + 2] != '*has extra registration'):
conname = l[j + 2]
else:
conname = l[j + 3]
await message.channel.send('Codeforce Contest')
await message.channel.send(conname + ' - ' +
'11 hr ' +
contimeleft[3:5] +
' min left')
await message.channel.send('<@&788645408343719947>')
# time.sleep(2)
elif (contimeleft[0:2] == '01'):
j = i
while (l[j] != 'Until closing' and j != 0):
j -= 1
if j <= 0:
conname = l[0]
else:
if (l[j + 2] != '*has extra registration'):
conname = l[j + 2]
else:
conname = l[j + 3]
await message.channel.send('Codeforce Contest')
await message.channel.send(conname + ' - ' +
'01 hr ' +
contimeleft[3:5] +
' min left')
await message.channel.send('<@&788645408343719947>')
# time.sleep(2)
elif (contimeleft[0:2] == '00'):
j = i
while (l[j] != 'Until closing' and j != 0):
j -= 1
if j <= 0:
conname = l[0]
else:
if (l[j + 2] != '*has extra registration'):
conname = l[j + 2]
else:
conname = l[j + 3]
await message.channel.send('Codeforce Contest')
await message.channel.send(conname + ' - ' +
'00 hr ' +
contimeleft[3:5] +
' min left')
await message.channel.send('<@&788645408343719947>')
# time.sleep(2)
await s(60*60)
client.run(os.getenv('TOKEN'))