Created
October 20, 2021 07:46
-
-
Save lucadentella/64c3996ceb1519797a22c0637024f9f1 to your computer and use it in GitHub Desktop.
python client with usb qrcode reader
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
# -*- coding: utf-8 -*- | |
import requests | |
import sys | |
from os import system, name | |
from time import sleep | |
import logging | |
import smtplib | |
import time | |
from os import system, name | |
#Email Variables | |
SMTP_SERVER = ‘smtp.gmail.com’ #Email Server (don’t change!) | |
SMTP_PORT = 587 #Server Port (don’t change!) | |
GMAIL_USERNAME = ‘inserire username gmail’ #change this to match your gmail account | |
GMAIL_PASSWORD = ‘inserire password’ #change this to match your gmail password | |
class Emailer: | |
def sendmail(self, recipient, subject, content): | |
#Create Headers | |
headers = [“Da: ” + GMAIL_USERNAME, “Oggetto: ” + subject, “A: ” + recipient, | |
“MIME-Version: 1.0”, “Content-Type: text/html”] | |
headers = “\r\n”.join(headers) | |
#Connect to Gmail Server | |
session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) | |
session.ehlo() | |
session.starttls() | |
session.ehlo() | |
#Login to Gmail | |
session.login(GMAIL_USERNAME, GMAIL_PASSWORD) | |
#Send Email & Exit | |
session.sendmail(GMAIL_USERNAME, recipient, headers + “\r\n\r\n” + content) | |
session.quit | |
sender = Emailer() | |
sendTo = ‘Inserire indirizzo mail a cui va inviata la segnalazione’ | |
emailSubject = “Anomalia GreenPass” | |
emailContent = “Rilevata Anomalia Certificazione” | |
log = logging.getLogger(__name__) | |
DEFAULT_CERTIFICATE_DB_JSON = ‘certs/roots/Digital_Green_Certificate_Signing_Keys.json’ | |
DEFAULT_CERTIFICATE_DIRECTORY = ‘certs’ | |
def clear(): | |
# for windows | |
if name == ‘nt’: | |
_ = system(‘cls’) | |
# for mac and linux(here, os.name is ‘posix’) | |
else: | |
_ = system(‘clear’) | |
class bcolors: | |
OKGREEN = ‘\033[92m’ | |
FAIL = ‘\033[91m’ | |
ENDC = ‘\033[0m’ | |
for line in sys.stdin: | |
clean = line.strip() | |
if (clean.startswith(‘HC1:’)): | |
payload = {‘dgc’: clean} | |
sleep(1) | |
clear() | |
r = requests.get(‘http://localhost:3000’, params=payload) | |
print (‘Return code: ‘, r.status_code, ‘ \nText: ‘, r.text) | |
if r.status_code == 200: | |
print (bcolors.OKGREEN + “GREEN PASS VALIDO” + bcolors.ENDC) | |
sleep(4) | |
clear() | |
else: | |
print (bcolors.FAIL + “GREEN PASS NON VALIDO” + bcolors.ENDC) | |
sender.sendmail(sendTo, emailSubject, emailContent) | |
sleep(4) | |
clear() | |
else: | |
print (“CODICE NON RICONOSCIUTO”) | |
sleep(2) | |
clear() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment