summaryrefslogtreecommitdiff
path: root/automated_slot_booking.py
blob: fc13afa01d24c3ec6fec680105e1d4208ef55963 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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"