diff --git a/Scan-it.py b/Scan-it.py new file mode 100644 index 0000000..f71ffd9 --- /dev/null +++ b/Scan-it.py @@ -0,0 +1,129 @@ +import PySimpleGUI as sg +import datetime +import barcode +import pyperclip +import keyboard +from PIL import ImageGrab +from pytesseract import pytesseract +# First the window layout in 2 columns + +#You must remove Tesserect for PYinstaller +path_to_tesseract = r"C:\Users\30783009\AppData\Local\Programs\Tesseract-OCR\tesseract.exe" + +rules = [[sg.Text("All scans copy output to clipboard:")]] +barker = [ + [ + sg.Text("Make Barcode:"), + sg.In(size=(25, 10), enable_events=True, key="-mkbox-",), + sg.Button(button_text="Encode", enable_events=True, key="-GO-"), + ], +] +newlot = [ + [ + sg.Text("Lot Pull:"), + sg.Input(size=(25, 10), enable_events=True, key="pull"), + sg.Button(button_text="Extract", enable_events=True, bind_return_key = True, key="noop"), + ], +] +# ----- Full layout ----- +layout = [ + [sg.Column(rules, justification="Left")], + [sg.Column(barker, justification="Right")], + [sg.Column(newlot, justification="Right")], +] + +window = sg.Window("Scanner Tool", layout) +arrrg = "404barcodenotfound" +#Functionality +def clippy(sluggers): + pyperclip.copy(sluggers) + pyperclip.paste() +def clippyB(mrpaperclip): + pyperclip.copy(mrpaperclip) + pyperclip.paste() + keyboard.press_and_release("backspace") + keyboard.press_and_release("backspace") +def readpicture(): + try: + foo = ImageGrab.grabclipboard() + pytesseract.tesseract_cmd = path_to_tesseract + pitty = pytesseract.image_to_string(foo) + foofighter = str(pitty) + clippy(foofighter) + print(foofighter) + return foofighter + except: + print("I don't think you have a picture on your clipboard.\nTry using [windows]+[shift]+[s] to take a screen grab that I can read.\n -Best Regards, The AI") +def Bark(): #I make barcodes + ean = barcode.get('code128', arrrg,) + ean.save("Pybar") +def longboifile(code): #I log what is done. + LOG = open("Loggy_Mclogface.log", "at") + LOG.write(str(code) + "||" + str(datetime.datetime.now()) + "\n") +def newt(): + lot = arrg.rsplit("|") + #print(str(lot[0])) + longboifile(lot[1]) + print(str(lot[1])) + clippy(str(lot[1])) +def log(): + maxleggy = len(arrg) + point1 = arrg[maxleggy-1] + point2 = arrg[maxleggy-2] + point3 = arrg[0] + point4 = arrg[1] + parse = arrg.strip(point1+point2+point3+point4) + print(parse) + longboifile(parse) + clippy(parse) +def lep(): + maxleggy = len(arrg) + point1 = arrg[maxleggy-1] + point2 = arrg[maxleggy-2] + parse = arrg.strip(arrg[0]) + parses = arrg.strip("+H435") + fparse = parses.strip(point1+point2) + print(fparse) + longboifile(fparse) + clippy(fparse) +def longcode(code): + lenth = len(code) + print(code[26:lenth]) + clippy(code[26:lenth]) +keyboard.add_hotkey(hotkey="h+f", callback=clippyB, args=["211698"]) +keyboard.add_hotkey(hotkey="t+g", callback=clippyB, args=["263611"]) +keyboard.add_hotkey(hotkey="ctrl+m+e", callback=clippyB, args=["230302"]) +keyboard.add_hotkey(hotkey="u+e", callback=clippyB, args=["259047"]) +keyboard.add_hotkey(hotkey="r+n", callback=clippyB, args=["228606"]) +keyboard.add_hotkey(hotkey="f+d", callback=clippyB, args=["486513284"]) +keyboard.add_hotkey(hotkey="a+d", callback=clippyB, args=["46985 ENTERPRISE CT\nSTE A-100\nWIXOM MI, 48393"]) +while True: + event, values = window.read() + if event == "Exit" or event == sg.WIN_CLOSED: + break + if event == "-GO-": + arrrg = values["-mkbox-"] + Bark() + clippy(arrrg) + longboifile(arrrg) + if event == "noop": + arrg = values["pull"] + if "" == arrg: + pass + elif "line" in arrg: + print("==========NEW=LINE=======================") + elif "yank" in arrg or "Yank" in arrg: + readpicture() + elif "+H435" in arrg: + lep() + elif "010" in arrg[0:3]: + longcode(arrg) + elif "|" in arrg: + arrg = values["pull"] + newt() + longboifile(arrg) + else: + log() + element = window["pull"] + element.update("") +window.close() \ No newline at end of file diff --git a/scanner.c b/scanner.c new file mode 100644 index 0000000..7e7a769 --- /dev/null +++ b/scanner.c @@ -0,0 +1,102 @@ +#include +#include + +char* reverseStrchr(const char* str, int character) { + char* result = NULL; + // Iterate through the string + while (*str != '\0') { + // If the character is found, update the result pointer + if (*str == character) { + result = (char*)str; + } + str++; + } + return result; +} + +void parse (char input[75]) { + //Morphs input assuming it's a scan to batch code + int lenny; + if (strcmp(&input[0], "") == 0) { + // pass + } + else if ('[' == input[0]) { // This handles OldSquare code + //printf("A step is, %d \n", step); + //printf("I got it!\n"); + char* entry = strchr(input, '$'); + //printf("Entry is: %p\n", entry); + char* exit = reverseStrchr(input, '\x1D'); + //printf("Exit is: %p\n", exit); + lenny = exit - entry - 1; + //printf("Lenny is: %d\n", lenny); + char result[lenny+1]; + strncpy(result, (entry+1), lenny); + result[lenny]='\0'; + //printf("%s\n", result); + strcpy(input, result); + } + else if ('+' == input[0]) { + //We could have Old top or Old Bot code here. + if ('$' == input[1]) { + //Old bot code + //+$13KM083319L + lenny = strlen(input); + //printf("Lenny is: %d\n", lenny); + char result[lenny-4]; + strncpy(result, &input[2], lenny-4); + result[lenny-4] = '\0'; + //printf("%s\n", result); + strcpy(input, result); + } + else { + printf("This Barcode does not contain a Batch code\n"); + } + } + else if ('0' == input[0]) { + char result[10]; + lenny = strlen(input); + strncpy(result, &input[26], lenny-26); + //printf("%s\n", result); + //printf("Lenny is: %d\n", lenny); + strcpy(input, result); + } + else if (strchr(input, '|')) { + //printf("I got it!\n"); + lenny = strlen(input); + //printf("Lenny is: %d\n", lenny); + char* entry = strchr(input, '|'); + char holder[75]; + strncpy(holder, entry+1, lenny-(entry-&input[0])); + //printf("Holder is: %s\n", holder); + entry = strchr(holder, '|'); + lenny = entry - &holder[0]; + //printf("Lenny is: %d\n", lenny); + char result[lenny]; + strncpy(result, &holder[0], lenny); + //printf("Result is: %s\n", result); + result[lenny] = '\0'; + strcpy(input, result); + } +} +int main() { + char input[75]; // 75 char limit + printf("Begin scanning (type 'exit' to quit):\n"); + + while (1) { + // Read user input + fgets(input, sizeof(input), stdin); + fputs("\033[A\033[2K",stdout); + strtok(input, "\n"); + parse(input); + + // Check if the user wants to exit + if (strcmp(input, "exit") == 0) { + printf("Exiting program. Goodbye!"); + break; // Exit the loop if the user types 'exit' + } + + // Print the input + printf("%s\n", input); + } + return 0; +} diff --git a/scanner.py b/scanner.py new file mode 100755 index 0000000..ae888c9 --- /dev/null +++ b/scanner.py @@ -0,0 +1,37 @@ + +def parse(arrg:str): + """ + i: Any raw string from scanner + o: (cat, bat) A tuple containing the catalog and batch info, + filling None as needed. + """ + if "" == arrg: + pass + elif "[)>" in arrg[0:3]: #These may need to be shifted up or down 1 based on how the application handles [rs][eot]and [gs] + cat = arrg[arrg.index("+H")+5:arrg.index("Q1")-2] + bat = arrg[arrg.index("$")+1:arrg.index("14D2")-1] + return (cat, bat) #This should instead return an implant. + elif "+H" in arrg[0:2]: + cat = arrg[5:-2] + return (cat, None) + elif "+$" in arrg[0:2]: + maxleggy = len(arrg) + backstrip = maxleggy - 2 + bat = arrg[2:backstrip] + return (None, bat) + elif "01" in arrg[0:2]: + #print("triggered modbar") + lenth = len(arrg) + bat = arrg[26:lenth] + return (None, bat) + elif "|" in arrg: + dance = arrg.rsplit("|") + cat = dance[0] + bat = dance[1] + return (cat, bat) + elif "+H12" in arrg: + cat = arrg[5:16] + bat = arrg[23:31] + return (cat, bat) + else: + return (arrg, None) \ No newline at end of file