Sample of simple web service using Python3 with Flask, Peewee and Telepot for Hour of Code of 2017.
First of all, download at your machine:
$ git clone https://github.com/ismtabo/hoc2017uva-python3.git
Install its only dependence:
- Virtualenv:
- To install on UNIX/Linux systems, execute below command:
$ sudo apt install virtualenv
- To install on other OS, follow instructions at official web page: https://virtualenv.pypa.io/en/stable/
- To install on UNIX/Linux systems, execute below command:
Sample has three different parts:
- Web service using Flask:
- Prepare virtual environment or use global system:
- Virtual environment:
$ virtualenv -p python3 venv $ source venv/bin/activate (venv) $ pip install -r requirements.txt
- Using already installed packages
- Virtual environment:
- Hello World using Flask
- Dynamic content with templates.
- Comment structure using:
- Templates
collections.namedtuple
- List of comments
- Form to post comments
- Prepare virtual environment or use global system:
- Persistence with peewee
- Comment class
- Create database of SQLite
- Add method to write comments into database
- Add method to retrieve comments from database
- Link database with flask
- Connect to Telegram using telepot
- Create bot using @BotFather
- Hello World with telepot using webhooks sample (each time a user talks to bot, it answers 'Hello World')
- Create function to add comments from telegram by:
/newcomment <comment>
Below tags identify several steps of the tutorial, you can show them at: https://github.com/ismtabo/hoc2017uva-python3/releases
To start with the tutorial, checkout first one with below command:
$ git checkout <tag_name>
For first step, it will be:
$ git checkout v1.0-flask-hello-world
In case, you want to advance in the tutorial but you already have done changes in the code, first discard this changes with:
$ git stash save --keep-index # Add changes to stash
$ git stash drop # Discard stash
Ànd then, checkout correct step's tag.
- Ismael Taboada: ismtabo