diff options
author | ttt | 2017-05-13 00:29:47 +0530 |
---|---|---|
committer | ttt | 2017-05-13 00:29:47 +0530 |
commit | abf599be33b383a6a5baf9493093b2126a622ac8 (patch) | |
tree | 4c5ab6e0d935d5e65fabcf0258e4a00dd20a5afa /automated_slot_booking.py | |
download | SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.gz SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.bz2 SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.zip |
added all server files
Diffstat (limited to 'automated_slot_booking.py')
-rw-r--r-- | automated_slot_booking.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/automated_slot_booking.py b/automated_slot_booking.py new file mode 100644 index 0000000..fc13afa --- /dev/null +++ b/automated_slot_booking.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +import random +import MySQLdb +import datetime +from time import gmtime, strftime + +db = MySQLdb.connect(host="localhost", ## your host, usually localhost ## + user="root", ## your username ## + passwd="OSCAD4229", ## your password ## + db="vlabs_sbhs") ## name of the data base ## + +## print "Opened database successfully" + +## Execution of querry +cursor5=db.cursor() +cu1=db.cursor() +querry1='SELECT * FROM tables_booking' +cu1.execute(querry1) + +## Datetime used when script runs +nowDate=datetime.datetime.now().date() +nowTime=str(datetime.datetime.now().time()) +SplittedTime=nowTime.split(":") +NowdaTe=str(nowDate) +NowdaTe=NowdaTe.strip() ## To remove extra spaces strip is used## + + +CurrentAccountIdList=[] +BookedSlotId=[] + +for DateTimeInBooking in cu1: + nn=str(DateTimeInBooking[6]) + daTe = nn[0:11] + tiMe=nn[11:13] + daTe=daTe.strip() + + if daTe==NowdaTe and int(SplittedTime[0])+1==int(DateTimeInBooking[3]): + CurrentAccountIdList.append(int(DateTimeInBooking[2])) + BookedSlotId.append(int(DateTimeInBooking[3])) +#print BookedSlotId,CurrentAccountIdList + + +querry2='SELECT *FROM tables_account' +cu2=db.cursor() +cu2.execute(querry2) + + +RequiredMidList=[] +for AccountIdFromTablesAccnt in cu2: + var=AccountIdFromTablesAccnt[0] + + for Id in range(len(CurrentAccountIdList)): + if long(CurrentAccountIdList[Id])==(AccountIdFromTablesAccnt[0]): + RequiredMidList.append(int(AccountIdFromTablesAccnt[9])) + +#print RequiredMidList + +SuperUserMidList=[Mid for Mid in range(1,41)] +#print SuperUserMidList + +MidsTobeBooked=[mId for mId in SuperUserMidList if mId not in RequiredMidList] +#print MidsTobeBooked + +for BookMid in range(len(MidsTobeBooked)): + ToInsert=[int((MidsTobeBooked[BookMid]))+40,int(SplittedTime[0])+1,(datetime.datetime.now()),(datetime.datetime.now()),(nowDate)] + cursor5.execute("INSERT INTO tables_booking(account_id,slot_id,created_at,updated_at,booking_date) VALUES(%s,%s,%s,%s,%s)",ToInsert) + db.commit() ## To update the table Changes in database ## + +## Closing all the object of Cursor +cu1.close() +cu2.close() +cursor5.close() +db.close() +## print "database closed successfully" |