https://github.com/paramt/q4t
Post scheduled quizzes on Telegram using a list of questions from Google Sheets
https://github.com/paramt/q4t
Last synced: 8 months ago
JSON representation
Post scheduled quizzes on Telegram using a list of questions from Google Sheets
- Host: GitHub
- URL: https://github.com/paramt/q4t
- Owner: paramt
- License: mit
- Created: 2020-03-17T14:10:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-21T06:44:26.000Z (about 2 years ago)
- Last Synced: 2025-04-12T20:45:00.300Z (about 1 year ago)
- Language: Python
- Size: 48.8 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :pencil: Scheduled Quizzes for Telegram
> Post scheduled quizzes on Telegram using a list of questions from Google Sheets
## :electric_plug: Set up
1. Click the Use this template button on GitHub and create a **private repository**
1. Create a Telegram bot
- Follow [these instructions](https://core.telegram.org/bots#creating-a-new-bot) to generate a token
- Add your token to `config.py`
- Add the bot to your channel or group and promote it to administrator
1. Connect to Google Sheets
- Go to [Google Developer Console](https://console.developers.google.com/apis/dashboard) and create a new project
- Click + ENABLE APIS AND SERVICES and enable the "Drive API" as well as the "Sheets API"
- Navigate to "APIs and Services" > "Credentials"
- Click + CREATE CREDENTIALS and select "Service account"
- Fill in the required fields, press CREATE, CONTINUE, and on the last step click + CREATE KEY to download a JSON file
- Upload the JSON file at the root of your GitHub repo and add the filename to the `credentials` variable in `config.py`
- Copy the [Google sheet template](https://docs.google.com/spreadsheets/u/1/d/1BE-ZbrkTejJloU_d953nYCKCqVSfoiQQCZ45Y3NSdtc/copy) and share it with the email address found in `client_email` in the JSON file
1. Configure options in `config.py`
| Option | Description | Type | Example |
| ------ | ----------- | ---- | ------- |
| `spreadsheet` | **Required** - The name of your Google sheet | String | Q4T Template |
| `channel` | **Required** - The unique identifier of your chat or the username of your channel (the part after t.me/ in the invite URL) | String | q4t_playground |
| `loop` | Whether of not the bot should loop through the questions if all the questions have been exhausted | Boolean | `True` |
| `anonymous` | Whether to keep the responses anonymous (Note: this *must* be set to `True` for channels) | Boolean | `True` |
**:warning: Make sure your repository is private, because your Google credentials and Telegram token is sensitive information.**
## :desktop_computer: Usage
You can add as many question/answer sets in your Google sheet as you want. You can also send an image alongside each question by providing the link to the image. The image will be sent immediately before the question. Everytime the script is run, it will send a quiz to the target chat or channel and increment the index in the `index` sheet. You can keep adding more question/answer sets indefinitely.
### Run at scheduled interval
To send quizzes at a certain interval, run `src/main.py` at the specific interval. The recommended way to do this is to use [GitHub Actions](https://github.com/features/actions). Here is a sample workflow you can put in `.github/workflows/main.yml` to send a quiz every day:
```yml
name: Send quiz
on:
schedule:
- cron: '0 0 * * *'
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '>=3.6'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Send quiz
run: python src/main.py
```
### Reset
To reset the spreadsheet, simply run `reset.py`. This will remove all questions and set the index to 2.