Archived
1
0
Fork 0

Add QRCode creation and send

This commit is contained in:
Ethanell 2020-11-07 13:18:53 +01:00
parent 248d750c97
commit 727c1e9ebc
2 changed files with 48 additions and 1 deletions

View file

@ -1,9 +1,42 @@
from datetime import datetime
from io import BytesIO
from qrcode import make
from telegram import Update
from telegram.ext import CallbackContext
from main import reasons
from main import reasons, database
local = {
"work": "travail",
"shopping": "achats",
"health": "sante",
"family": "famille",
"handicap": "handicap",
"sport_animal": "sport_animaux",
"injunction": "convocation",
"missions": "missions",
"children": "enfants"
}
def create(update: Update, context: CallbackContext):
reason = map(lambda r: local[r], reasons[update.effective_chat.id][update["_effective_user"]["id"]])
del reasons[update.effective_chat.id][update["_effective_user"]["id"]]
date = datetime.now().strftime('%d/%m/%Y a %Hh%M')
img = make(f"Cree le: {date};\n"
f"Nom: {database[update['_effective_user']['id']]['last_name']};\n"
f"Prenom: {database[update['_effective_user']['id']]['first_name']};\n"
f"Naissance: {database[update['_effective_user']['id']]['birth_date']} a "
f"{database[update['_effective_user']['id']]['birth_city']};\n"
f"Adresse: {database[update['_effective_user']['id']]['address']};\n"
f"Sortie: {date}\n"
f"Motifs: {', '.join(reason)};")
photo = BytesIO()
photo.name = "QRCode.jpeg"
img.save(photo, "JPEG")
photo.seek(0)
context.bot.send_photo(chat_id=update.effective_chat.id, photo=photo)

14
requirements.txt Normal file
View file

@ -0,0 +1,14 @@
APScheduler==3.6.3
certifi==2020.6.20
cffi==1.14.3
cryptography==3.2.1
decorator==4.4.2
Pillow==8.0.1
pkg-resources==0.0.0
pycparser==2.20
python-telegram-bot==13.0
pytz==2020.4
qrcode==6.1
six==1.15.0
tornado==6.1
tzlocal==2.1