Created
February 28, 2022 09:15
-
-
Save ShahriyarR/0640b8b4ef7b5c1ac69095db1a2ea2f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate(first_name: str, last_name: str, birth_date: str, **vaccinations: Manufacturer) -> None: | |
""" | |
Generate your vaccination QR code. | |
Args: | |
first_name (str): name of the vaccinated person | |
last_name (str): surname of the vaccindate person | |
birth_date (str): birthday of the vaccinated person in YYYY-MM-DD format | |
**vaccinations (Manufacturer): vaccination information as date=manufacturer | |
Return: None | |
""" | |
# TODO: handle duplicate or wrong dates. | |
qr_code = QRCode( | |
name=f"{first_name} {last_name}", | |
birth=birth_date, | |
vaccinations=[ | |
Vaccination(manufacturer=manufacturer, date=datetime.strptime(date, "%Y-%m-%d")) | |
for date, manufacturer in vaccinations.items() | |
], | |
) | |
res = requests.get( | |
f"http://api.qrserver.com/v1/create-qr-code/?data={qr_code}", stream=True | |
) | |
if res.status_code != 200: | |
raise Exception("QR code cannot be generated by QR Code Generator API.") | |
with open("qr_code.png", "wb") as f: | |
res.raw.decode_content = True | |
shutil.copyfileobj(res.raw, f) | |
print("QR code has been generated.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment