30 lines
763 B
Python
Executable File
30 lines
763 B
Python
Executable File
#!/usr/bin/python3
|
|
import RPi.GPIO as GPIO
|
|
import pymysql
|
|
import sys
|
|
import os
|
|
import time as t
|
|
from datetime import datetime as dt
|
|
|
|
pressed = int(sys.argv[1])
|
|
|
|
db = pymysql.connect(host='localhost', user='pi2', passwd='emb20', db='parking_lot')
|
|
cur = db.cursor()
|
|
|
|
try:
|
|
query = "select spaceID from spaces where usedID = False"
|
|
cur.execute(query)
|
|
db.commit()
|
|
spaces = cur.fetchall()
|
|
now = dt.now()
|
|
date = now.date()
|
|
query = "update spaces set date = '{0}', startTime = '{1}', endTime= NULL, usedID = True where spaceID = {2}".format(date, time, spaces[0][0])
|
|
cur.execute(query)
|
|
db.commit()
|
|
except IndexError:
|
|
status ="<script>alert('Sorry, but there are no spaces left')</script>"
|
|
print(status)
|
|
|
|
db.close()
|
|
sys.exit(0)
|