Last active
June 5, 2018 20:59
-
-
Save alyssasgable/c07bcd827fe2cf68a597a0b698a95c45 to your computer and use it in GitHub Desktop.
[Scanning Project]
This file contains 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
#!/bin/sh | |
# launcher.sh | |
# navigate to home directory, then to this directory, then execute python script, then back home | |
cd / | |
cd home/pi/Desktop | |
sudo python scanner.py | |
cd / |
This file contains 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
.sidenav { | |
height: 100%; | |
width: 220px; | |
position: fixed; | |
z-index: 1; | |
top: 0; | |
right: 0; | |
background-color: #111; | |
overflow-x: hidden; | |
padding-top: 20px; | |
text-align: center; | |
} | |
.sidenav a { | |
padding: 8px 8px 8px 32px; | |
text-decoration: none; | |
font-size: 25px; | |
color: #818181; | |
display: block; | |
transition: 0.3s; | |
} | |
.sidenav a:hover { | |
color: #f1f1f1; | |
} | |
.sidenav .closebtn { | |
position: absolute; | |
top: 0; | |
right: 25px; | |
font-size: 36px; | |
margin-left: 50px; | |
} | |
#main { | |
transition: margin-left .5s; | |
padding: 16px; | |
} | |
@media screen and (max-height: 450px) { | |
.sidenav {padding-top: 15px;} | |
.sidenav a {font-size: 18px;} | |
} | |
hr { | |
height: 12px; | |
border: 0; | |
box-shadow: inset 0 12px 12px -12px rgba(0, 0, 0, 0.5); | |
} | |
#scans { | |
font-size: 30px; | |
} | |
* { | |
font-family: Helvetica, sans-serif; | |
} |
This file contains 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
window.onload = function what(){ | |
(function countdown(remaining) { | |
if(remaining <= 0) | |
location.reload(true); | |
document.getElementById('countdown').innerHTML = remaining; | |
setTimeout(function(){ countdown(remaining - 1); }, 1000); | |
})(60); | |
} |
This file contains 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
#!/user/bin/env python | |
import evdev, subprocess | |
import time, datetime | |
from evdev import InputDevice, categorize, ecodes | |
import requests | |
import statusUpdate | |
from threading import Thread | |
import csv | |
import json | |
import pygame.mixer | |
#assigns scanners to input device | |
readyCut1 = InputDevice('/dev/input/event0') | |
cutComplete2 = InputDevice('/dev/input/event1') | |
cutComplete3 = InputDevice('/dev/input/event2') | |
cutComplete4 = InputDevice('/dev/input/event3') | |
sewn5 = InputDevice('/dev/input/event4') | |
sewn6 = InputDevice('/dev/input/event5') | |
sewn7 = InputDevice('/dev/input/event6') | |
scancodes = { | |
# Scancode: ASCIICode | |
0: None, 1: u'ESC', 2: u'1', 3: u'2', 4: u'3', 5: u'4', 6: u'5', 7: u'6', 8: u'7', 9: u'8', | |
10: u'9', 11: u'0', 12: u'-', 13: u'=', 14: u'BKSP', 15: u'TAB', 16: u'q', 17: u'w', 18: u'e', 19: u'r', | |
20: u't', 21: u'y', 22: u'u', 23: u'i', 24: u'o', 25: u'p', 26: u'[', 27: u']', 28: u'CRLF', 29: u'LCTRL', | |
30: u'a', 31: u's', 32: u'd', 33: u'f', 34: u'g', 35: u'h', 36: u'j', 37: u'k', 38: u'l', 39: u';', | |
40: u'"', 41: u'`', 42: u'LSHFT', 43: u'\\', 44: u'z', 45: u'x', 46: u'c', 47: u'v', 48: u'b', 49: u'n', | |
50: u'm', 51: u',', 52: u'.', 53: u'/', 54: u'RSHFT', 56: u'LALT', 57: u' ', 100: u'RALT' | |
} | |
capscodes = { | |
0: None, 1: u'ESC', 2: u'!', 3: u'@', 4: u'#', 5: u'$', 6: u'%', 7: u'^', 8: u'&', 9: u'*', | |
10: u'(', 11: u')', 12: u'_', 13: u'+', 14: u'BKSP', 15: u'TAB', 16: u'Q', 17: u'W', 18: u'E', 19: u'R', | |
20: u'T', 21: u'Y', 22: u'U', 23: u'I', 24: u'O', 25: u'P', 26: u'{', 27: u'}', 28: u'CRLF', 29: u'LCTRL', | |
30: u'A', 31: u'S', 32: u'D', 33: u'F', 34: u'G', 35: u'H', 36: u'J', 37: u'K', 38: u'L', 39: u':', | |
40: u'\'', 41: u'~', 42: u'LSHFT', 43: u'|', 44: u'Z', 45: u'X', 46: u'C', 47: u'V', 48: u'B', 49: u'N', | |
50: u'M', 51: u'<', 52: u'>', 53: u'?', 54: u'RSHFT', 56: u'LALT', 57: u' ', 100: u'RALT' | |
} | |
#setup vars | |
x = '' | |
caps = False | |
polist = [] | |
delay = 0 | |
scans = {} | |
#sets up sound | |
pygame.mixer.init() | |
goodscan = pygame.mixer.Sound('goodscan.wav') | |
duplicatescan = pygame.mixer.Sound('duplicateScan.wav') | |
badscan = pygame.mixer.Sound('badScan.wav') | |
#grab provides exclusive access to the devices | |
readyCut1.grab | |
cutComplete2.grab | |
cutComplete3.grab | |
cutComplete4.grab | |
sewn5.grab | |
sewn6.grab | |
sewn7.grab | |
def readyCutScan(): | |
# gets current date and time | |
now = datetime.datetime.now() | |
time_str = now.strftime('%Y-%m-%d %H:%M:%S') | |
#setup vars | |
x = '' | |
caps = False | |
polist = [] | |
delay = 0 | |
prevScan = '' | |
for event in readyCut1.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
data = categorize(event) # Save the event temporarily to introspect it | |
if data.scancode == 42: | |
if data.keystate == 1: | |
caps = True | |
if data.keystate == 0: | |
caps = False | |
if data.keystate == 1: # Down events only | |
if caps: | |
key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
else: | |
key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
if (data.scancode != 42) and (data.scancode != 28): | |
x += key_lookup | |
if(data.scancode == 28): | |
print (x) | |
if x == "Delay": | |
delay = 1 | |
x='' | |
continue; | |
if delay == 1: | |
polist.extend([x, "Delay 1"]) | |
delay = 0 | |
print (polist) | |
if len(x) < 14: | |
badscan.play() | |
error = " was scanned and is less than 14 characters long." | |
with open("scanner_log.txt", "a") as error_log: | |
error_log.write("%s Error: %s %s %s \n" % (time_str, x, error, "1")) | |
print(x + " was scanned and is less than 14 characters long.") | |
x='' | |
continue; | |
if prevScan == x: | |
duplicatescan.play() | |
print("Duplicate Scan") | |
x='' | |
continue; | |
else: | |
goodscan.play() | |
polist.extend([x, "Ready To Cut", "1"]) | |
scans = { | |
"timestamp": time_str, | |
"ponum": x, | |
"status": polist[1], | |
"scanner": polist[2] | |
} | |
csv = open('backups.txt', 'a+') | |
row = scans["timestamp"] + "," + scans["ponum"] + "," + scans["status"] + "," + scans["scanner"] | |
csv.write(row) | |
csv.write('\n') | |
print (polist) | |
prevScan = x | |
x='' | |
statusUpdate.databaseUpdate(polist) | |
polist = [] | |
def cutCompleteScan1(): | |
# gets current date and time | |
now = datetime.datetime.now() | |
time_str = now.strftime('%Y-%m-%d %H:%M:%S') | |
#setup vars | |
x = '' | |
caps = False | |
polist = [] | |
delay = 0 | |
prevScan = '' | |
for event in cutComplete2.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
data = categorize(event) # Save the event temporarily to introspect it | |
if data.scancode == 42: | |
if data.keystate == 1: | |
caps = True | |
if data.keystate == 0: | |
caps = False | |
if data.keystate == 1: # Down events only | |
if caps: | |
key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
else: | |
key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
if (data.scancode != 42) and (data.scancode != 28): | |
x += key_lookup | |
if(data.scancode == 28): | |
print (x) | |
if x == "Delay": | |
delay = 1 | |
x='' | |
continue; | |
if delay == 1: | |
polist.extend([x, "Delay", "2"]) | |
delay = 0 | |
print (polist) | |
if len(x) < 14: | |
badscan.play() | |
error = " was scanned and is less than 14 characters long." | |
with open("scanner_log.txt", "a") as error_log: | |
error_log.write("%s Error: %s %s %s \n" % (time_str, x, error, "2")) | |
print(x + " was scanned and is less than 14 characters long.") | |
x='' | |
continue; | |
if prevScan == x: | |
duplicatescan.play() | |
print("Duplicate Scan") | |
x='' | |
continue; | |
else: | |
goodscan.play() | |
polist.extend([x, "Cut Complete", "2"]) | |
scans['timestamp'] = time_str | |
scans['ponum'] = x | |
scans['status'] = polist[1] + ' ' + polist[2] | |
with open('backupscans.txt', 'a') as outfile: | |
json.dump(scans, outfile, indent=1) | |
print (polist) | |
prevScan = x | |
x='' | |
statusUpdate.databaseUpdate(polist) | |
polist = [] | |
def cutCompleteScan2(): | |
# gets current date and time | |
now = datetime.datetime.now() | |
time_str = now.strftime('%Y-%m-%d %H:%M:%S') | |
#setup vars | |
x = '' | |
caps = False | |
polist = [] | |
delay = 0 | |
prevScan = '' | |
for event in cutComplete3.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
data = categorize(event) # Save the event temporarily to introspect it | |
if data.scancode == 42: | |
if data.keystate == 1: | |
caps = True | |
if data.keystate == 0: | |
caps = False | |
if data.keystate == 1: # Down events only | |
if caps: | |
key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
else: | |
key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
if (data.scancode != 42) and (data.scancode != 28): | |
x += key_lookup | |
if(data.scancode == 28): | |
print (x) | |
if x == "Delay": | |
delay = 1 | |
x='' | |
continue; | |
if delay == 1: | |
polist.extend([x, "Delay", "3"]) | |
delay = 0 | |
print (polist) | |
if len(x) < 14: | |
badscan.play() | |
error = " was scanned and is less than 14 characters long." | |
with open("scanner_log.txt", "a") as error_log: | |
error_log.write("%s Error: %s %s %s \n" % (time_str, x, error, "3")) | |
print(x + " was scanned and is less than 14 characters long.") | |
x='' | |
continue; | |
if prevScan == x: | |
duplicatescan.play() | |
print("Duplicate Scan") | |
x='' | |
continue; | |
else: | |
goodscan.play() | |
polist.extend([x, "Cut Complete", "3"]) | |
print (polist) | |
scans = { | |
"timestamp": time_str, | |
"ponum": x, | |
"status": polist[1], | |
"scanner": polist[2] | |
} | |
csv = open('backups.txt', 'a+') | |
row = scans["timestamp"] + "," + scans["ponum"] + "," + scans["status"] + "," + scans["scanner"] | |
csv.write(row) | |
csv.write('\n') | |
print (polist) | |
prevScan = x | |
x='' | |
statusUpdate.databaseUpdate(polist) | |
polist = [] | |
def cutCompleteScan3(): | |
# gets current date and time | |
now = datetime.datetime.now() | |
time_str = now.strftime('%Y-%m-%d %H:%M:%S') | |
#setup vars | |
x = '' | |
caps = False | |
polist = [] | |
delay = 0 | |
prevScan = '' | |
for event in cutComplete4.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
data = categorize(event) # Save the event temporarily to introspect it | |
if data.scancode == 42: | |
if data.keystate == 1: | |
caps = True | |
if data.keystate == 0: | |
caps = False | |
if data.keystate == 1: # Down events only | |
if caps: | |
key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
else: | |
key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
if (data.scancode != 42) and (data.scancode != 28): | |
x += key_lookup | |
if(data.scancode == 28): | |
print (x) | |
if x == "Delay": | |
delay = 1 | |
x='' | |
continue; | |
if delay == 1: | |
polist.extend([x, "Delay", "4"]) | |
delay = 0 | |
print (polist) | |
if len(x) < 14: | |
badscan.play() | |
error = " was scanned and is less than 14 characters long." | |
with open("scanner_log.txt", "a") as error_log: | |
error_log.write("%s Error: %s %s %s \n" % (time_str, x, error, "4")) | |
print(x + " was scanned and is less than 14 characters long.") | |
x='' | |
continue; | |
if prevScan == x: | |
duplicatescan.play() | |
print("Duplicate Scan") | |
x='' | |
continue; | |
else: | |
goodscan.play() | |
polist.extend([x, "Cut Complete", "4"]) | |
print (polist) | |
scans = { | |
"timestamp": time_str, | |
"ponum": x, | |
"status": polist[1], | |
"scanner": polist[2] | |
} | |
csv = open('backups.txt', 'a+') | |
row = scans["timestamp"] + "," + scans["ponum"] + "," + scans["status"] + "," + scans["scanner"] | |
csv.write(row) | |
csv.write('\n') | |
print (polist) | |
prevScan = x | |
x='' | |
statusUpdate.databaseUpdate(polist) | |
polist = [] | |
def sewnScanner1(): | |
# gets current date and time | |
now = datetime.datetime.now() | |
time_str = now.strftime('%Y-%m-%d %H:%M:%S') | |
#setup vars | |
x = '' | |
caps = False | |
polist = [] | |
delay = 0 | |
prevScan = '' | |
for event in sewn5.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
data = categorize(event) # Save the event temporarily to introspect it | |
if data.scancode == 42: | |
if data.keystate == 1: | |
caps = True | |
if data.keystate == 0: | |
caps = False | |
if data.keystate == 1: # Down events only | |
if caps: | |
key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
else: | |
key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
if (data.scancode != 42) and (data.scancode != 28): | |
x += key_lookup | |
if(data.scancode == 28): | |
print (x) | |
if x == "Delay": | |
delay = 1 | |
x='' | |
continue; | |
if delay == 1: | |
polist.extend([x, "Delay", "5"]) | |
delay = 0 | |
print (polist) | |
if len(x) < 14: | |
badscan.play() | |
error = " was scanned and is less than 14 characters long." | |
with open("scanner_log.txt", "a") as error_log: | |
error_log.write("%s Error: %s %s %s \n" % (time_str, x, error, "5")) | |
print(x + " was scanned and is less than 14 characters long.") | |
x='' | |
continue; | |
if prevScan == x: | |
duplicatescan.play() | |
print("Duplicate Scan") | |
x='' | |
continue; | |
else: | |
goodscan.play() | |
polist.extend([x, "Sewn and Ready To Pack", "5"]) | |
print (polist) | |
scans = { | |
"timestamp": time_str, | |
"ponum": x, | |
"status": polist[1], | |
"scanner": polist[2] | |
} | |
csv = open('backups.txt', 'a+') | |
row = scans["timestamp"] + "," + scans["ponum"] + "," + scans["status"] + "," + scans["scanner"] | |
csv.write(row) | |
csv.write('\n') | |
print (polist) | |
prevScan = x | |
x='' | |
statusUpdate.databaseUpdate(polist) | |
polist = [] | |
def sewnScanner2(): | |
# gets current date and time | |
now = datetime.datetime.now() | |
time_str = now.strftime('%Y-%m-%d %H:%M:%S') | |
#setup vars | |
x = '' | |
caps = False | |
polist = [] | |
delay = 0 | |
prevScan = '' | |
for event in sewn6.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
data = categorize(event) # Save the event temporarily to introspect it | |
if data.scancode == 42: | |
if data.keystate == 1: | |
caps = True | |
if data.keystate == 0: | |
caps = False | |
if data.keystate == 1: # Down events only | |
if caps: | |
key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
else: | |
key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
if (data.scancode != 42) and (data.scancode != 28): | |
x += key_lookup | |
if(data.scancode == 28): | |
print (x) | |
if x == "Delay": | |
delay = 1 | |
x='' | |
continue; | |
if delay == 1: | |
polist.extend([x, "Delay", "6"]) | |
delay = 0 | |
print (polist) | |
if len(x) < 14: | |
badscan.play() | |
error = " was scanned and is less than 14 characters long." | |
with open("scanner_log.txt", "a") as error_log: | |
error_log.write("%s Error: %s %s %s \n" % (time_str, x, error, "6")) | |
print(x + " was scanned and is less than 14 characters long.") | |
x='' | |
continue; | |
if prevScan == x: | |
duplicatescan.play() | |
print("Duplicate Scan") | |
x='' | |
continue; | |
else: | |
goodscan.play() | |
polist.extend([x, "Sewn and Ready To Pack", "6"]) | |
print (polist) | |
scans = { | |
"timestamp": time_str, | |
"ponum": x, | |
"status": polist[1], | |
"scanner": polist[2] | |
} | |
csv = open('backups.txt', 'a+') | |
row = scans["timestamp"] + "," + scans["ponum"] + "," + scans["status"] + "," + scans["scanner"] | |
csv.write(row) | |
csv.write('\n') | |
prevScan = x | |
x='' | |
statusUpdate.databaseUpdate(polist) | |
polist = [] | |
def sewnScanner3(): | |
# gets current date and time | |
now = datetime.datetime.now() | |
time_str = now.strftime('%Y-%m-%d %H:%M:%S') | |
#setup vars | |
x = '' | |
caps = False | |
polist = [] | |
delay = 0 | |
prevScan = '' | |
for event in sewn7.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
data = categorize(event) # Save the event temporarily to introspect it | |
if data.scancode == 42: | |
if data.keystate == 1: | |
caps = True | |
if data.keystate == 0: | |
caps = False | |
if data.keystate == 1: # Down events only | |
if caps: | |
key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
else: | |
key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX | |
if (data.scancode != 42) and (data.scancode != 28): | |
x += key_lookup | |
if(data.scancode == 28): | |
print (x) | |
if x == "Delay": | |
delay = 1 | |
x='' | |
continue; | |
if delay == 1: | |
polist.extend([x, "Delay", "7"]) | |
delay = 0 | |
print (polist) | |
if len(x) < 14: | |
badscan.play() | |
error = " was scanned and is less than 14 characters long." | |
with open("scanner_log.txt", "a") as error_log: | |
error_log.write("%s Error: %s %s %s \n" % (time_str, x, error, "7")) | |
print(x + " was scanned and is less than 14 characters long.") | |
x='' | |
continue; | |
if prevScan == x: | |
duplicatescan.play() | |
print("Duplicate Scan") | |
x='' | |
continue; | |
else: | |
goodscan.play() | |
polist.extend([x, "Sewn and Ready To Pack", "7"]) | |
print (polist) | |
scans = { | |
"timestamp": time_str, | |
"ponum": x, | |
"status": polist[1], | |
"scanner": polist[2] | |
} | |
csv = open('backups.txt', 'a+') | |
row = scans["timestamp"] + "," + scans["ponum"] + "," + scans["status"] + "," + scans["scanner"] | |
csv.write(row) | |
csv.write('\n') | |
prevScan = x | |
x='' | |
statusUpdate.databaseUpdate(polist) | |
polist = [] | |
#starts all functions | |
t1 = Thread(target = readyCutScan) | |
t2 = Thread(target = cutCompleteScan1) | |
t3 = Thread(target = cutCompleteScan2) | |
t4 = Thread(target = cutCompleteScan3) | |
t5 = Thread(target = sewnScanner1) | |
t6 = Thread(target = sewnScanner2) | |
t7 = Thread(target = sewnScanner3) | |
t1.start() | |
t2.start() | |
t3.start() | |
t4.start() | |
t5.start() | |
t6.start() | |
t7.start() |
This file contains 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
<?php | |
header("refresh: 60;"); | |
?> | |
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="scanner.css"> | |
<script type="text/javascript" src="scanner.js"></script> | |
</head> | |
<div class="sidenav"> | |
<a href="#home" class="active">Home</a> | |
<a href="https://drive.google.com/open?id=1Ybjgvjh8lYIJ2x60ZT8w5CYF9wQtzqf4RgKPL80JCzk">Documentation</a> | |
<a href="#graphs">Graphs</a> | |
<a href="#qr">QR Codes</a> | |
<h3 style="color:white; text-align: center;" id="countdown"</h3> | |
</div> | |
<div id="main"> | |
<h1>Scanned Items:</h1> | |
<hr> | |
<div id="scans"> | |
<?php | |
$scanner_log = array_reverse(file('/home/pi/Desktop/scanner_log.txt')); | |
foreach($scanner_log as $scan) { | |
echo $scan . "<br>"; | |
} | |
?> | |
</div> | |
</div> | |
</html> |
This file contains 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
#Alyssa Gable | |
#This handles all processes after scanner gets string from QR Code | |
#Updated 6/5/2018 | |
#!/user/bin/env python | |
import MySQLdb | |
import datetime | |
import logging | |
import logging.handlers | |
import smtplib | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
import pygame.mixer | |
import time, datetime | |
import requests | |
# connects to database | |
servername = "192.168.172.51"; | |
username = "scanner"; | |
password = "NV6BW2mn9C$"; | |
dbname = "scan"; | |
# email address and pass | |
email = "helpdesk@onlinecommercegroup.com" | |
passwrd = "p3tM3gud" | |
#sets up sound | |
pygame.mixer.init() | |
goodscan = pygame.mixer.Sound('goodScan.wav') | |
badscan = pygame.mixer.Sound('badScan.wav') | |
def databaseUpdate(polist): | |
# set up the SMTP server | |
s = smtplib.SMTP(host='smtp-mail.outlook.com', port=587) | |
s.starttls() | |
s.login(email, passwrd) | |
db = MySQLdb.connect(servername, username, password, dbname) | |
# creates cursor | |
cursor = db.cursor() | |
# sets timezone | |
cursor.execute("""SET time_zone = 'US/Central'""") | |
# initializes delay status and po number | |
ponum = polist[0] | |
scanner = polist[2] | |
status = polist[1] + ' ' + scanner | |
delay = 0 | |
previousScans = [] | |
oldStatus = '' | |
error = [] | |
count = 0 | |
# gets current date and time | |
now = datetime.datetime.now() | |
time_str = now.strftime('%Y-%m-%d %H:%M:%S') | |
if len(ponum) >= 14: | |
with open("scanner_log.txt", "a") as log: | |
log.write("%s %s %s \n" % (time_str, ponum, status)) | |
if 'Ready To Cut' in status: | |
print(ponum + " sent to database.") | |
cursor.execute("""INSERT INTO scan.prod_status (po_num, status, timestamp) VALUES (%s, %s, %s)""", | |
(ponum, status, time_str)) | |
else: | |
cursor.execute("SELECT status FROM scan.prod_status WHERE po_num = %s", [ponum]) | |
rows = cursor.fetchall() | |
for oldStatus in rows: | |
previousScans.append(oldStatus) | |
print('Previous Scans: ' + "".join([str(i) for i in previousScans])) | |
scans = str(previousScans) | |
if len(previousScans) >= 0: | |
if "Sewn" in status: | |
if scans.find("Ready To Cut") == -1: | |
error.append("Ready To Cut") | |
if scans.find("Cut Complete") == -1: | |
error.append("Cut Complete") | |
if "Cut Complete" in status: | |
if scans.find("Ready To Cut") == -1: | |
error.append("Ready To Cut") | |
if len(error) > 0: | |
msg = MIMEMultipart() | |
message = "PO %s was scanned with status '%s' and is missing the following scans: \n%s \n\n%s" % (ponum, status, error, time_str) | |
msg['From'] = 'helpdesk@onlinecommercegroup.com' | |
msg['To'] = 'alyssa@ocg.io' | |
msg['Subject'] = "%s: Missed Scans" % (ponum) | |
msg.attach(MIMEText(message, 'plain')) | |
s.sendmail(msg['From'], msg['To'], msg.as_string()) | |
print("There was a missing scan. An email has been sent to it@ocg.io") | |
cursor.execute("""INSERT INTO scan.prod_status (po_num, status, timestamp) VALUES (%s, %s, %s)""", | |
(ponum, status, time_str)) | |
print(ponum + " sent to database") | |
db.commit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment