74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
from ZKFingerprint import Fingerprint, UserInfoEncoder
|
|
import json
|
|
import curses
|
|
|
|
def add_new_machine():
|
|
ip_address = input("Enter the IP address of the new machine: ")
|
|
port = input("Enter the port of the new machine: ")
|
|
office_id = input("Enter the office ID of the new machine: ")
|
|
return Fingerprint(ip_address, port, office_id)
|
|
|
|
def main_menu(stdscr):
|
|
curses.curs_set(0)
|
|
stdscr.clear()
|
|
stdscr.refresh()
|
|
|
|
height, width = stdscr.getmaxyx()
|
|
title = "Attendance Machine System"
|
|
menu_win = curses.newwin(10, 40, (height // 2) - 5, (width // 2) - 20)
|
|
menu_win.box()
|
|
|
|
menu = [
|
|
"1. Add new attendance machine",
|
|
"2. Get machine status",
|
|
"3. Get all user data",
|
|
"4. Get specific user data",
|
|
"5. Export user data to JSON",
|
|
"6. Exit"
|
|
]
|
|
|
|
while True:
|
|
menu_win.clear()
|
|
stdscr.border(0)
|
|
stdscr.addstr(1, (width // 2) - (len(title) // 2), title)
|
|
menu_win.clear()
|
|
menu_win.box()
|
|
for idx, item in enumerate(menu):
|
|
x = 2
|
|
y = 2 + idx
|
|
menu_win.addstr(y, x, item)
|
|
stdscr.refresh()
|
|
menu_win.refresh()
|
|
|
|
key = stdscr.getch()
|
|
if key == ord('1'):
|
|
machine = add_new_machine()
|
|
menu_win.addstr(8, 2, "New machine added successfully!")
|
|
elif key == ord('2'):
|
|
menu_win.addstr(8, 2, "Machine Status : " + machine.getStatus())
|
|
elif key == ord('3'):
|
|
menu_win.addstr(8, 2, str(machine.getUserInfo()))
|
|
elif key == ord('4'):
|
|
user_pin = input("Enter the user PIN: ")
|
|
menu_win.addstr(8, 2, str(machine.getUserInfo(user_pin)))
|
|
elif key == ord('5'):
|
|
decoded_data = machine.getUserInfo()
|
|
data_dict = {"data": decoded_data}
|
|
json_data = json.dumps(data_dict, indent=4, cls=UserInfoEncoder)
|
|
file_path = 'user_info2.json'
|
|
with open(file_path, 'w') as file:
|
|
file.write(json_data)
|
|
menu_win.addstr(8, 2, f"JSON data saved to {file_path}")
|
|
elif key == ord('6'):
|
|
break
|
|
else:
|
|
menu_win.addstr(8, 2, "Invalid choice. Please try again.")
|
|
|
|
stdscr.refresh()
|
|
menu_win.refresh()
|
|
stdscr.getch()
|
|
|
|
if __name__ == "__main__":
|
|
# initial office=10.35.14.10
|
|
machine = Fingerprint('10.35.7.12', '80', '0')
|
|
curses.wrapper(main_menu) |