Created
April 14, 2017 04:24
-
-
Save wwwins/4f5678ff1d6715a9e3b6421e178e8b53 to your computer and use it in GitHub Desktop.
A small daemon for rfid reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# isobard.py | |
# read rfid -> pkill -> get user info -> exec face detecter | |
# | |
# connect to it with: | |
# echo -n "0001864282 edith"|nc -w 0 localhost 5555 | |
# | |
from socket import * | |
from time import sleep | |
import subprocess | |
import string | |
import random | |
PROCESS_FILE_NAME = "isobar-face-detect-gevent.py" | |
def exec_face_detecter(data): | |
username = get_user_info() | |
subprocess.call(['/usr/local/bin/isobar-face-detect.sh', data, username]) | |
def pkill(pname): | |
subprocess.call(['pkill', '-f', pname]) | |
def get_user_info(): | |
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(5)) | |
def main(): | |
print("server starting") | |
sock = socket() | |
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR,1) | |
sock.bind(('',5555)) | |
sock.listen(5) | |
while True: | |
client, addr = sock.accept() | |
print('Connection', addr) | |
data = client.recv(100) | |
if len(data) > 0: | |
print('recv:',data) | |
pkill(PROCESS_FILE_NAME) | |
sleep(0.2) | |
exec_face_detecter(data) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment