-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
66 lines (53 loc) · 1.75 KB
/
Main.py
File metadata and controls
66 lines (53 loc) · 1.75 KB
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
import mysql.connector
import datetime
from datetime import date
import socket
status = True
# mysql server (DataBase)
mysql = mysql.connector.connect(
host = "",
user = "",
password = "",
database = "",
port =
)
cursor = mysql.cursor(buffered=True)
# fix variable
enter = "IN"
leave = "OUT"
while status == True:
# current date
date = datetime.datetime.now()
created_at = datetime.datetime.now()
# location (get current location from host name)
lc = socket.gethostname()
# user input
user_input = input()
# pull data from DataBase 1
sql = f"SELECT * FROM student_info WHERE MC={user_input}"
cursor.execute(sql)
ID = cursor.fetchone()
# breaking down variable pulled from DataBase 1
stu_id, name, year, micode = ID
# select user that match with describsion (user input, today, descending order)
cursor.execute(f"SELECT * FROM get_insert \
WHERE micode={user_input} and date=current_date and location='{lc}' \
ORDER BY created_at DESC")
cf = cursor.fetchone()
# push data back to DataBase 2 for storing
query_enter = f"INSERT INTO get_insert (id, name, year, location, status, date, micode) \
VALUES ({stu_id},'{name}','{year}','{lc}','{enter}','{date}',{micode})"
query_leave = f"INSERT INTO get_insert (id, name, year, location, status, date, micode) \
VALUES ({stu_id},'{name}','{year}','{lc}','{leave}','{date}',{micode})"
# if condition to check for IN/OUT
if cf == None:
cursor.execute(query_enter)
else:
if cf[4] == 'IN':
cursor.execute(query_leave)
else:
cursor.execute(query_enter)
mysql.commit()
# close loop and DataBase
status = False
mysql.close()