Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
robogroup
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
matteo perini
robogroup
Commits
ef5501cf
Commit
ef5501cf
authored
Jan 03, 2025
by
matteo perini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prima versione
parent
54bda0e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
324 additions
and
7 deletions
+324
-7
applicazione.py
applicazione.py
+35
-6
my_lib.py
my_lib.py
+289
-1
No files found.
applicazione.py
View file @
ef5501cf
import
time
import
os
from
termcolor
import
colored
os
.
system
(
'cls'
if
os
.
name
==
'nt'
else
'clear'
)
from
my_lib
import
registra_cliente
,
registra_prodotto
,
cerca_cliente_per_prodotto
,
scarica_prodotto
,
lista_clienti
,
scarica_cliente
,
lista_prodotti
def
mostra_menu
():
os
.
system
(
'cls'
if
os
.
name
==
'nt'
else
'clear'
)
#print(chr(27) + "[2J")
# questa riga serve per cancellare il terminale
os
.
system
(
'cls'
if
os
.
name
==
'nt'
else
'clear'
)
# questa riga serve per cancellare il terminale
#print(chr(27) + "[2J")
#Qui sotto creiamo il menù
print
(
colored
(
"
\n
Seleziona l'operazione da effettuare selezionando il numero del menù:
\n
"
,
"green"
,
attrs
=
[
"bold"
]))
print
(
colored
(
" [1] Registrazione nuovo cliente"
,
"cyan"
,
attrs
=
[
"bold"
]))
print
(
colored
(
" [2] Acquisto prodotto"
,
"cyan"
,
attrs
=
[
"bold"
]))
print
(
colored
(
" [3] Restituzione prodotto"
,
"cyan"
,
attrs
=
[
"bold"
]))
print
(
colored
(
" [4]
Ricerca numero cliente per nome
"
,
"cyan"
,
attrs
=
[
"bold"
]))
print
(
colored
(
" [4]
Controlla la lista dei clienti
"
,
"cyan"
,
attrs
=
[
"bold"
]))
print
(
colored
(
" [5] Ricerca proprietario di un prodotto"
,
"cyan"
,
attrs
=
[
"bold"
]))
print
(
colored
(
" [6] Rimuovi cliente dal db"
,
"cyan"
,
attrs
=
[
"bold"
]))
print
(
colored
(
" [7] Ricerca i prodotti di un cliente"
,
"cyan"
,
attrs
=
[
"bold"
]))
print
(
colored
(
"
\n
[0] Esci"
,
"magenta"
,
attrs
=
[
"bold"
]))
n
=
input
(
""
)
#leggiamo il tasto inserito dall'utente
if
n
.
isnumeric
()
:
#se è stato inserito un numero entriamo nella funzione che lo controlla
if
int
(
n
)
in
[
1
,
2
,
3
,
4
,
5
,
0
]:
#il numero è tra le possibilità ipotizzate?
if
int
(
n
)
in
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
0
]:
#il numero è tra le possibilità ipotizzate?
if
int
(
n
)
==
0
:
#se è stato schiacciato lo 0 scrivo arrivederci e esco
print
(
"Arrivederci!"
)
return
0
#serve per uscire dalla funzione
elif
int
(
n
)
==
1
:
registra_cliente
()
time
.
sleep
(
3
)
mostra_menu
()
elif
int
(
n
)
==
2
:
registra_prodotto
()
time
.
sleep
(
3
)
mostra_menu
()
elif
int
(
n
)
==
3
:
scarica_prodotto
()
time
.
sleep
(
3
)
mostra_menu
()
elif
int
(
n
)
==
4
:
lista_clienti
()
time
.
sleep
(
3
)
mostra_menu
()
elif
int
(
n
)
==
5
:
cerca_cliente_per_prodotto
()
time
.
sleep
(
3
)
mostra_menu
()
elif
int
(
n
)
==
6
:
scarica_cliente
()
time
.
sleep
(
3
)
mostra_menu
()
elif
int
(
n
)
==
7
:
lista_prodotti
()
time
.
sleep
(
3
)
mostra_menu
()
else
:
print
(
"ok"
)
time
.
sleep
(
2
)
...
...
my_lib.py
View file @
ef5501cf
import
RPi.GPIO
as
GPIO
from
mfrc522
import
SimpleMFRC522
import
sqlite3
import
time
def
cerca_cliente_per_prodotto
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
def
leggi_prodotto
():
try
:
print
(
"Ciao, avvicina il prodotto al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
n
=
leggi_prodotto
()
database
=
cur
.
execute
(
'SELECT n_cliente FROM prodotti WHERE n_rfid=?;'
,(
n
,))
yy
=
database
.
fetchall
()
if
len
(
yy
)
>
0
:
for
row
in
yy
:
xx
=
row
[
0
]
print
(
xx
)
cliente
=
cur
.
execute
(
'SELECT * FROM persone WHERE n_card=?;'
,(
xx
,))
#for i in cliente:
print
(
cliente
.
fetchone
())
else
:
print
(
"Prodotto non associato a nessun cliente"
)
def
registra_prodotto
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
cur
.
execute
(
"""CREATE TABLE IF NOT EXISTS prodotti (
id INTEGER PRIMARY KEY,
n_rfid TEXT NOT NULL UNIQUE,
n_cliente TEXT NOT NULL);"""
)
def
leggi_cliente
():
try
:
print
(
"Ciao, avvicina il tag del cliente al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
def
leggi_prodotto
():
try
:
print
(
"Ciao, avvicina il prodotto al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
#n = input("Quale e il tuo nome?")
#c = input("Quale e il tuo cognome?")
codice_cliente
=
leggi_cliente
()
time
.
sleep
(
2
)
codice_prodotto
=
leggi_prodotto
()
try
:
cur
.
execute
(
"INSERT INTO prodotti(n_rfid, n_cliente) VALUES(?, ?)"
,(
codice_prodotto
,
codice_cliente
))
#print("ciao")
print
(
"Ciao "
,
codice_cliente
,
" abbiamo registrato il prodotto numero : "
,
codice_prodotto
)
con
.
commit
()
cur
.
close
()
except
:
print
(
"Codice non corretto"
)
def
scarica_prodotto
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
#cur.execute("""CREATE TABLE IF NOT EXISTS prodotti (
#id INTEGER PRIMARY KEY,
#n_rfid TEXT NOT NULL UNIQUE,
#n_cliente TEXT NOT NULL);""")
# def leggi_cliente():
# try:
# print("Ciao, avvicina il tag del cliente al ricevitore!")
# id,text = reader.read()
# print(id)
# #print(text)
# except:
# pass
# finally:
# GPIO.cleanup()
# return int(id)
def
leggi_prodotto
():
try
:
print
(
"Ciao, avvicina il prodotto al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
#n = input("Quale e il tuo nome?")
#c = input("Quale e il tuo cognome?")
#codice_cliente = leggi_cliente()
#time.sleep(2)
codice_prodotto
=
leggi_prodotto
()
try
:
cur
.
execute
(
"DELETE FROM prodotti WHERE n_rfid=?;"
,(
codice_prodotto
,))
#print("ciao")
#print("Ciao ", codice_cliente , " abbiamo registrato il prodotto numero : ", codice_prodotto)
con
.
commit
()
cur
.
close
()
except
:
print
(
"Codice non corretto"
)
def
scarica_cliente
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
#cur.execute("""CREATE TABLE IF NOT EXISTS prodotti (
#id INTEGER PRIMARY KEY,
#n_rfid TEXT NOT NULL UNIQUE,
#n_cliente TEXT NOT NULL);""")
def
leggi_cliente
():
try
:
print
(
"Ciao, avvicina il tag del cliente al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
# def leggi_prodotto():
# try:
# print("Ciao, avvicina il prodotto al ricevitore!")
# id,text = reader.read()
# print(id)
# #print(text)
# except:
# pass
# finally:
# GPIO.cleanup()
# return int(id)
#n = input("Quale e il tuo nome?")
#c = input("Quale e il tuo cognome?")
codice_cliente
=
leggi_cliente
()
#time.sleep(2)
#codice_prodotto = leggi_prodotto()
try
:
cur
.
execute
(
"DELETE FROM persone WHERE n_card=?;"
,(
codice_cliente
,))
#print("ciao")
#print("Ciao ", codice_cliente , " abbiamo registrato il prodotto numero : ", codice_prodotto)
con
.
commit
()
cur
.
close
()
print
(
"Cliente rimosso dal database"
)
except
:
print
(
"Codice non corretto"
)
def
registra_cliente
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
cur
.
execute
(
"""CREATE TABLE IF NOT EXISTS persone (
id INTEGER PRIMARY KEY,
nome TEXT NOT NULL,
cognome TEXT NOT NULL,
n_card TEXT NOT NULL UNIQUE);"""
)
def
leggi_codice
():
try
:
print
(
"Ciao, avvicina il tag RFID al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
print
(
text
)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
id
n
=
input
(
"Quale e il tuo nome?"
)
c
=
input
(
"Quale e il tuo cognome?"
)
a
=
leggi_codice
()
try
:
b
=
int
(
a
)
cur
.
execute
(
"INSERT INTO persone(nome, cognome, n_card) VALUES(?, ?, ?)"
,(
n
,
c
,
a
))
print
(
"Ciao "
,
n
,
" la tua tessera ha il numero : "
,
b
)
con
.
commit
()
cur
.
close
()
except
:
print
(
"Codice non corretto"
)
def
leggi_cliente
():
reader
=
SimpleMFRC522
()
...
...
@@ -28,4 +258,62 @@ def leggi_prodotto():
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
\ No newline at end of file
return
int
(
id
)
def
lista_clienti
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
cur
.
execute
(
"""CREATE TABLE IF NOT EXISTS persone (
id INTEGER PRIMARY KEY,
nome TEXT NOT NULL,
cognome TEXT NOT NULL,
n_card TEXT NOT NULL UNIQUE);"""
)
database
=
cur
.
execute
(
"""SELECT * FROM persone;"""
)
for
row
in
database
:
print
(
row
)
def
lista_prodotti
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
# cur.execute("""CREATE TABLE IF NOT EXISTS persone (
# id INTEGER PRIMARY KEY,
# nome TEXT NOT NULL,
# cognome TEXT NOT NULL,
# n_card TEXT NOT NULL UNIQUE);""")
def
leggi_cliente
():
reader
=
SimpleMFRC522
()
try
:
print
(
"Ciao, avvicina il tag del cliente al ricevitore!"
)
id
,
text
=
reader
.
read
()
#print(id)
#print(text)
except
:
print
(
"C'è stato un errore di lettura. Ripetere l'operazione!"
)
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
codice_cliente
=
leggi_cliente
()
#time.sleep(2)
#codice_prodotto = leggi_prodotto()
try
:
database
=
cur
.
execute
(
"SELECT * FROM prodotti WHERE n_cliente=?;"
,(
codice_cliente
,))
#print("ciao")
#print("Ciao ", codice_cliente , " abbiamo registrato il prodotto numero : ", codice_prodotto)
for
row
in
database
:
print
(
row
)
#con.commit()
cur
.
close
()
#print("+")
except
:
print
(
"Codice non corretto"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment