To fight Corona Virus, our Prime Minister has declared lockdown for 21 days in all over the country. And so, our college decided to take online lectures and also, sent us a google form which is to be filled every day for each lecture to fill attendance. Filling form 4 times a day with the subject name and corresponding time and professor details is a tedious task. But also, Attendance is Engineer's Only Motivation to attend lectures.
And So, I decided to use Python and to write a script to automate this tedious task.
As usual, I started by searching on google to see how can we submit the google form using python script. And I came to know that Every Google Form Input element has a "name" attribute attached to it and we can use it to send the data for the corresponding field.
So, I opened the google form in chrome and Started inspecting Input element in which I will be filling the data, and I found a bunch of ss-form-entry objects with name attribute like
" name = entry.<id> "
I copied every name attribute value of the field.
Now, In Python I created a dictionary with the value of name attributes that we copied from the browser as keys and the data that I want to fill in the corresponding field as it's value.
Then I created a dictionary with Day Name(Monday, Tuesday, etc.) as keys and the lectures' details as list as values.
And put both the dictionaries in a function that returns the list of different data dictionaries of the current day.
And, finally the function for sending the form response using POST method of requests library. It takes two arguments - URL and data(here, data_dictionary), respectively.
Note: Change the URL of google form by replacing '/viewform' at the end of the URL with 'formResponse'. Now, your URL should look like this
And that's it, now I just have to run this script once a day and it will fill my attendance for all the lectures of that day.
I can also deploy it on a server like PythonAnyWhere or DigitalOcean and it can run by itself every day, but as I'm home quarantine for the 21 Days, I have more than enough time to run it manually every day.🤓🤓
You can find the full code here : AutoFill Google Form