-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
122 lines (94 loc) · 2.98 KB
/
Copy pathmain.py
File metadata and controls
122 lines (94 loc) · 2.98 KB
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
import discord
import os
from discord.ext import commands
import asyncio
from keep_alive import keep_alive
import pytz
from selenium import webdriver
import time
from datetime import datetime
bot = commands.Bot(command_prefix='!')
client = discord.Client()
username = "username" #replace with your lms username
password = "password" #replace with your lms password
def get_time():
tz_NY = pytz.timezone('Asia/Kolkata')
datetime_NY = datetime.now(tz_NY)
now = datetime_NY.strftime("%H:%M:%S - (%d/%m)")
return now
def markit():
driver = webdriver.Firefox()
url = 'https://eduserver.nitc.ac.in/login/index.php'
driver.get(url)
driver.find_element_by_xpath('//*[@id="username"]').send_keys(username)
driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
element = driver.find_element_by_xpath(
'/html/body/div[1]/div[2]/div/section/div[2]/div[2]/div[1]/div/div[2]/form/div[3]/button')
driver.execute_script("arguments[0].click();", element)
print('cool')
driver.implicitly_wait(10)
time.sleep(3)
try:
driver.find_element_by_partial_link_text('Attendance').click()
except:
return False
time.sleep(2)
driver.implicitly_wait(5)
driver.find_element_by_link_text('Go to activity').click()
driver.implicitly_wait(5)
a = 1
b = 0
t = 0
while (a and t <= 25):
print("value of t is: "+ str(t))
list = driver.find_elements_by_link_text('Submit attendance')
if (list != []):
b = 1
if (b):
time.sleep(2)
driver.find_element_by_link_text('Submit attendance').click()
time.sleep(2)
driver.implicitly_wait(2)
driver.find_elements_by_class_name('statusdesc')[0].click()
driver.find_element_by_name('submitbutton').click()
time.sleep(2)
a = 0
driver.close()
return True
else:
driver.implicitly_wait(1)
driver.refresh()
time.sleep(5)
t += 5
driver.close()
return False
async def finder():
await bot.wait_until_ready()
channel = bot.get_channel(int(os.environ['channelId']))
k = 0
while (True):
try:
state = markit()
except:
time.sleep(100)
continue
if (state):
time_now = get_time()
await channel.send("attendance marked at " + time_now)
else:
time_now = get_time()
await channel.send("looped for " + str(k) + " times" + " at " + time_now)
k += 1
time.sleep(10)
await asyncio.sleep(10)
@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.content.startswith('$hello'):
await message.channel.send('Hello!')
print("start")
keep_alive()
bot.loop.create_task(finder())
bot.run(os.environ['token'])