This repository has been archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.py
30 lines (28 loc) · 1.23 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
import sys
import pymysql
import subprocess
import time
print("Fase 2: Verifica del codice inserito")
nome = "Err" #Variabile inizializzata ad errore. Se avra successo la query verra cambiata nel nome della persona
db = pymysql.connect("localhost","Accesso","BONO","campusArcesso") #Dati di accesso al DB e connessione
print("Connessione al Database")
cursor = db.cursor() #Specifica un cursore per la lettura dei dati
try:
cursor.execute("SELECT nome FROM studenti WHERE pin = %s;", sys.argv[1]) #esegue la query
res = cursor.fetchall() #Prende tutti i risultati
print("Verifica effettuata\n")
for row in res: #Per ogni riga prende il nome (dovrebbe essercene solo una)
nome = row[0]
#print(nome) #Debug
except:
nome = "Err" #Vuole qualcosa qui...
#Se c'è un errore di esecuzione la variabile nome sarà err (come impostata prima). Sarà riconosciuta da arduino come errore
#print(nome) #Debug
else:
#print(nome) # Debug
time.sleep(5)
processo = subprocess.check_output(['python3', 'send.py', nome]) #Apre il programma che pubblica sul topic di risposta
print(processo.decode("utf-8")) #Dovrebbe stampare l'output del processo
db.close() #Chiude la connessione al DB
sys.exit() #Termina l'esecuzione di questo script