Skip to content

Commit

Permalink
docs: update readme about the random fill script
Browse files Browse the repository at this point in the history
  • Loading branch information
tienthanh214 committed Jun 15, 2024
1 parent acc5355 commit 5f43366
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
72 changes: 60 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
# 🚀 Google Form AutoFill and Submit
Vietnamese version [here](https://tienthanh214.github.io/computer%20science/autofill-and-submit-ggform/)

Someone send us a Google-form, and we need to fill it everyday or maybe every hour to report something.
It seems to be boring, so I just think to write a script to build this auto-bot using **Python 3**
Someone send us a Google-form, and we need to fill it everyday or maybe every hour to report something. It seems to be boring, so I just think to write a script to automate the process using **Python 3**

This is a simple and lightweight script to automatically fill and submit a Google form.
It's also include a request body *generator*, you can simply copy and paste a Google form URL, eliminating the need for manual inspection.
This is a simple and lightweight script to automatically fill and submit a Google form with random data. The script is customizable, allowing you to fill the form with the data you need.

It's also include a request body *generator* for those who prefer to manually input data, you can simply copy and paste a Google form URL, eliminating the need for manual inspection.

*This document will guide you through the process of creating a Python script to automatically fill and submit a Google form.*

## Table of Contents
- [🚀 Google Form AutoFill and Submit](#-google-form-autofill-and-submit)
- [Table of Contents](#table-of-contents)
- [Features](#features)
- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [Access and get the URL](#access-and-get-the-url)
- [Extract information](#extract-information)
- [Automatically](#automatically)
- [Manually](#manually)
- [Note](#note)
- [Write the Python script](#write-the-python-script)
- [Fill form](#fill-form)
- [Submit form](#submit-form)
- [AutoFill and Submit](#autofill-and-submit)
- [Run the Script](#run-the-script)
- [Customize the Script](#customize-the-script)
- [Limitations](#limitations)

## Features
- [x] Supports multiple pages Google forms
- [x] Supports Google Forms that collect email addresses (Responder input)
- [x] Automatically generates the request body using the `form.py` script
- [x] Auto-fills the form with random values (customizable) and submits it

## Prerequisites
- Python 3.x
- `requests` library (`pip install requests` or `pip install -r requirements.txt`)

# Just build it
## Create and access URL
# Getting Started
If you only want to fill and submit a Google form with random data, or customize the script to fill the form with the data you need, you can skip to the [AutoFill and Submit](#autofill-and-submit) section.

Below are the steps to create a Python script to fill and submit a Google form. If you want to skip the manual inspection step, you can use the `form.py` script to automatically generate the request body (as described in the [Extract information Automatically](#automatically) section).

## Access and get the URL
The URL of the Google form will look like this:
```
https://docs.google.com/forms/d/e/form-index/viewform
Expand All @@ -29,9 +59,9 @@ Just copy the Google form URL and run [form.py](form.py) script. The script will
```bash
python form.py <your-gg-form-url>
```
The result will be printed to the console (by default) or saved to a file if the `-o` option is used.
The result will be printed to the console (by default), or saved to a file if the `-o` option is used.

For more information use the help command
For more information, please use the help command
```bash
python form.py -h
```
Expand All @@ -48,16 +78,17 @@ Each of the input elements which we need to fill data has format: ```name = "ent

Try to fill each input box to know its id

***Note***:
### Note
- If the form requires email, please add the `emailAddress` field
- For multiple pages form, please add the `pageHistory` field with a comma-separated list of page numbers (starting from 0) if the form has multiple pages. For example, a 4-page form would have `"pageHistory": "0,1,2,3"`
- For multiple pages forms, please add the `pageHistory` field with a comma-separated list of page numbers (starting from 0). For example, a 4-page form would have `"pageHistory": "0,1,2,3"`

## Write the Python script

### Fill form
Create a dictionary in which keys are the name attributes of each input element, and values are the data you need to fill out

```py
# example
def fill_form():
name = get_name_by_day()
date, hour = str(get_gmt_time()).split(' ')
Expand All @@ -78,7 +109,7 @@ def fill_form():
# Hour
"entry.855769839": hour[0] + 'h',
# Checkbox
"entry.819260047": ["Cà phê", "Bể bơi"],
"entry.819260047": ["Cafe", "Fences"],
# One choice
"entry.1682233942": "Okay"
}
Expand All @@ -100,5 +131,22 @@ submit(url, fill_form())
```
Done!!!

## Limitations
# AutoFill and Submit
## Run the Script
Run the `main.py` script with the Google form URL as an argument to automatically fill and submit the form with ***random data***
```bash
python main.py <your-gg-form-url>
```
For example:
```bash
python main.py 'https://docs.google.com/forms/u/0/d/e/1FAIpQLSdwcwvrOeBG200L0tCSUHc1MLebycACWIi3qw0UBK31GE26Yg/viewform'
```
Use `-r`/`--required` to only fill the form with required fields
```bash
python main.py 'https://docs.google.com/forms/u/0/d/e/1FAIpQLSdwcwvrOeBG200L0tCSUHc1MLebycACWIi3qw0UBK31GE26Yg/viewform' -r
```
## Customize the Script
The [main.py](main.py) script is a simple example of how to use the `form.py` script to automatically fill and submit a Google form. You can customize the `fill_form` function to fill the form with the data you need.

# Limitations
Please note that this script currently operates only with Google Forms that do not require user authentication.
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def main(url, only_required = False):
try:
payload = generate_request_body(url, only_required = only_required)
submit(url, payload)
print("Done!!!")
except Exception as e:
print("Error!", e)

Expand Down

0 comments on commit 5f43366

Please sign in to comment.