Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
teleexit/callbackQuery/create.py

43 lines
1.4 KiB
Python
Raw Normal View History

2020-11-07 13:18:53 +01:00
from datetime import datetime
from io import BytesIO
from qrcode import make
2020-11-07 12:16:52 +01:00
from telegram import Update
from telegram.ext import CallbackContext
2020-11-07 13:18:53 +01:00
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"
}
2020-11-07 12:16:52 +01:00
def create(update: Update, context: CallbackContext):
2020-11-07 13:18:53 +01:00
reason = map(lambda r: local[r], reasons[update.effective_chat.id][update["_effective_user"]["id"]])
2020-11-07 12:16:52 +01:00
del reasons[update.effective_chat.id][update["_effective_user"]["id"]]
2020-11-07 13:18:53 +01:00
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)
2020-11-07 12:16:52 +01:00