Automating My Online Class Attendance(Fun with Python)

Attending online class is a very tedious task, students have to face many difficulties like network issue,audio issues and many more and if you are an Indian student then attendance is also a big issue for you because in India it's necessary to maintain the 75 percent attendance criteria.


Last month our college decided to conduct online zoom and for same purpose they  designed a moodle portal for taking attendance of the students , so criteria was that any random time teacher will unlock the Attendance portal and you have to mark the attendance within 5 to 10 min , after that your portal will close. Sometimes teacher close the portal within 2 mins , so one has to be very fast and concentrated in class. Moreover marking attendance was not also to easy, you have to follow series of event.

login to portal -> select your subject from dropdown -> click on Attendance Button -> One more link to Attendance form ->Click on Present Radio button -> Submit the Form.

As You can see such a tedious task it is, In our country attendance is given very much importance and I think it is right at some point but the main problem was that sometimes when I was in washroom or drinking water the teacher took the attendance and I was marked absent, sometimes I got to indulge in understanding the topic that I forgot to  mark the attendance also the criteria for marking the attendance was to much time consuming.

So I decided to write a python script which scrap my college website and check if attendance button is active or not and if it is active then it plays a audio message for me that attendance button is active and after waiting for few seconds it automatically mark my attendance.

Sharing Code Would not be possible for me as my college is a private entity but i will give you a small idea of what I did, so I used basically 4 python modules for this automation stuff .

1. requests
2. BeautifulSoup from bs4 module
3. gtts(google Text to speech)
4. time

As we all know that whenever we visit a website either we fetch content from the websites server(GET request) or we post content(Post content), there are many other requests like Delete but most common are get and post. So the requests module of python provide functionality for sending all the requests.
So By using requests module I created a session,so what is session , session is something which help us to store cookies. My moodle portal requires sign in to perform any task so if I didn't create session then each time I have to login to my portal , so what session did is it stores my login details and cookies as a browser did.

After Creating session I post my login details to college login page with the help of python requests module.

Quote :- Don't trust what you see there might be much more behind the scene.

There was a simple form  on login page of moodle website in which I was supposed to fill my username and password so i right clicked on my username field and found the name of the field which was username and similarly password was named as password. so I passed a dictionary which contain username and it's corresponding value(which was my user name) and password and it's corresponding value(my password). I thought that I only need to pass these two parameters in my post request but i was wrong , I tried for approx 2 hours and i was unable to login then after an hour of inspection I found that there was a hidden input which was also the part of post request, the movement i added that hidden input name and value to my dictionary and then to post request ...Hurray !!! I was logged in to my college website.

Old School Tip :- If You are filling a form using post request then always inspect the complete form tag because there might be one or more hidden input values and these values are necessary to post to fill the form successfully.

So here is the glimpse of code till now .

So after logging in , we have to select our subject , for now let us select subject 2,after selecting subject 2 let us click on attendance button. After clicking the attendance button we will check if attendance button is active or not  if it is active then we will  post the form with inputs name and value and if it is not available  we will sleep for  200 sec and then again check if button is available.

I know it's difficult to understand the code without seeing the actual website at each step but it's not possible for me to show you the exact website. But soon I will post a blog by setting up my own moodle portal and automating it.

If You have noticed , I have written this code for only one subject , this is because for all subjects attendance button location varies so generalizing it would be tedious task so I have written different script for each subject. whenever I have to leave my DAA class for a while I will run python3 daa.py and my computer will take care of my attendance.

Your suggestion matters a lot , If you have any suggestion or query feel free to write it in comment section.

Comments

Popular posts from this blog

How To Run Jupyter Notebook , Pandas And Numpy On M1 MacBook ?

M1 MacBook Air For Development (A Student Review)

How to sell your mobile phone online easily