Exemple #1
0
def fetchANs(bols, client, workOrderLocation):
    #     pdfs=[]
    with open('J:\Spencer\Fetched Hapag.txt', 'r') as myfile:
        data = myfile.read().replace('\n', '')

    doneBols = []
    failedPDFs = ""
    for bol in bols:
        if bol != "" and not bol in doneBols:
            if bol in data and skipPopup(bol):
                continue
            doneBols.append(bol)
            tickets = client.ticket_search(Title="WOSD0001 - " + bol,
                                           From="@[Hh][Ll][Aa][Gg]")
            getPdf(tickets, bol)
            with open('J:\Spencer\Fetched Hapag.txt', 'a+') as myfile:
                myfile.write(bol + "\n")


#             print(pdf)
#             if pdf:
#                 pdfs.append(pdf)
#                 with open(workOrderLocation+"\\"+"DOs.pdf", 'wb') as f:
#                     input_streams = []
#                     try:
#                         # First open all the files, then produce the output file, and
#                         # finally close the input files. This is necessary because
#                         # the data isn't read from the input files until the write
#                         # operation. Thanks to
#                         # https://stackoverflow.com/questions/6773631/problem-with-closing-python-pypdf-writing-getting-a-valueerror-i-o-operation/6773733#6773733
#                         i=0
#                         for input_file in pdfs:
#                             f1=open(input_file, 'r+b')
#                             input_streams.append(f1)
#                             i+=1
#                         writer = PdfFileWriter()
#                         for reader in map(PdfFileReader, input_streams):
#                             for n in range(reader.getNumPages()):
#                                 writer.addPage(reader.getPage(n))
#                         writer.write(f)
#                     finally:
#                         for f in input_streams:
#                             f.close()
#             else:
#                 failedPDFs = "\n"+bol+failedPDFs

#     for pdf in pdfs:
#         os.remove(pdf)

    if failedPDFs != "":
        popUpOK("Could not find the following WOs: " + failedPDFs)
Exemple #2
0
def fetchANs(bols, client, workOrderLocation):
    pdfs = []
    doneBols = []
    failedPDFs = ""
    for bol in bols:
        if bol != "" and not bol in doneBols:
            doneBols.append(bol)
            tickets = client.ticket_search(Title="Delivery Order for BL# " +
                                           bol,
                                           From="@msc.com")
            pdf = getPdf(tickets)
            if pdf:
                pdfs.append(pdf)
                with open(workOrderLocation + "\\" + "DOs.pdf", 'wb') as f:
                    input_streams = []
                    try:
                        # First open all the files, then produce the output file, and
                        # finally close the input files. This is necessary because
                        # the data isn't read from the input files until the write
                        # operation. Thanks to
                        # https://stackoverflow.com/questions/6773631/problem-with-closing-python-pypdf-writing-getting-a-valueerror-i-o-operation/6773733#6773733
                        i = 0
                        for input_file in pdfs:
                            f1 = open(input_file, 'r+b')
                            input_streams.append(f1)
                            i += 1
                        writer = PdfFileWriter()
                        for reader in map(PdfFileReader, input_streams):
                            for n in range(reader.getNumPages()):
                                writer.addPage(reader.getPage(n))
                        writer.write(f)
                    finally:
                        for f in input_streams:
                            f.close()
            else:
                failedPDFs = "\n" + bol + failedPDFs

    for pdf in pdfs:
        os.remove(pdf)

    if failedPDFs != "":
        popUpOK("Could not find the following BOLs: " + failedPDFs)
Exemple #3
0
 def callbackCont():
     if T1.get("1.0", constants.END).strip() == "":
         popUpOK("Please list the container numbers to release")
     else:
         pattern = compile(r"[a-zA-Z]{4}[0-9]{6,7}")
         deleteNumber = 1
         cNumbers = T1.get("1.0", constants.END).splitlines()
         for container in cNumbers:
             container = container.replace(" ", "")
             #                 if len(container)>9:
             if not pattern.match(container):
                 print("Invalid container number: \n" + container)
                 deleteNumber += 1
             else:
                 if sendRelease(container, driver, account):
                     #                     T1.delete("1.0", "2.0")
                     T1.delete(
                         str(deleteNumber) + ".0",
                         str(deleteNumber + 1) + ".0")
                 else:
                     deleteNumber += 1
Exemple #4
0
 def callbackCont():
     if T1.get("1.0", constants.END).strip() == "":
         popUpOK("Please list the target WOs")
     else:
         bols.append(T1.get("1.0", constants.END).splitlines())
         top.destroy()
Exemple #5
0
#         os.remove(pdf)

    if failedPDFs != "":
        popUpOK("Could not find the following WOs: " + failedPDFs)

if __name__ == '__main__':
    #     sys.argv=r"a C:\Users\ssleep\Documents\Maersk fetcher".split()
    #     sys.argv=r"a J:\All motor routings\2019\Week 3\HAPAG".split()
    workOrderLocation = ''
    for i in range(len(sys.argv)):
        if i != 0:
            workOrderLocation += sys.argv[i]
            if i != len(sys.argv) - 1:
                workOrderLocation += " "

    filterwarnings("ignore")

    client = Client("https://core.seaportint.com/", "testadmin", "testpass")
    a = client.session_create()
    if (a):
        print("Connected to OTRS as Testadmin")

    if isdir(workOrderLocation):
        bols = getBOLs()
        for i in range(len(bols)):
            bols[i] = bols[i].replace("WOSD0001 - ", "")
        fetchANs(bols, client, workOrderLocation)
    else:
        popUpOK("Please send a folder to the program")

    #pyinstaller "C:\Users\ssleep\workspace\Pull Hapag WO\Automator\__init__.py" --distpath "J:\Spencer\Pull Hapag WO" --noconsole -y
Exemple #6
0
def setupDM(folderPath, drivers):
#     app = Application(backend="win32").connect(path = r"C:\DM54_W16\DM54_W16.exe")
#     
# #     top_windows = []
# #     EnumWindows(windowEnumerationHandler, top_windows)
# #     for i in top_windows:
# #         if 'Dispatch-Mate' in i[1]:
# #             SetWindowPos(i[0], None, 0, 0, 1920, 1080, SWP_SHOWWINDOW)
# #             SetForegroundWindow(i[0])
#             
#     
#     winChildren = ""
#      
#     dialogs = app.windows()
#     
#     for x in dialogs:
#         if handleprops.classname(x) == "WinDevObject":
#             winChildren = handleprops.children(x)
#             topWindow = x
#             break
    
    clickTuple = False
    
    click(50, 350)
    fore = win32gui.GetForegroundWindow()
    DMFore = "Dispatch-Mate" in win32gui.GetWindowText(fore)
    while not DMFore:
        top = Tk()
        L1 = Label(top, text="Please maximize DispatchMate and the PB in the left monitor")
        L1.grid(row=0, column=0)
         
        def callbackDM():
            top.destroy()
         
        MyButton4 = Button(top, text="OK", width=10, command=callbackDM)
        MyButton4.grid(row=1, column=0)
     
        popUp(top, w=350, h=50, widget = MyButton4)
         
        click(50, 350)
        fore = win32gui.GetForegroundWindow()
        DMFore = "Dispatch-Mate" in win32gui.GetWindowText(fore)
        
#     i=0
    for driver in drivers:
#         if i>0: 
    
        click(327, 33)
         
        sleep(3)
         
        click(399, 281)
        
        if driver.PARS[-1]=="A" or driver.PARS[-1]=="B" or driver.PARS[-1]=="C":
            typewrite(driver.PARS[-7:-1])
        else:
            typewrite(driver.PARS[-6:])
         
        press("enter")
         
        sleep(3)
         
        click(1857, 100)
        
        sleep(0.5)
         
        click(569, 900)
         
        month = str(pickupDate.month)
        if len(month)<2:
            month = "0" + month
        typewrite(month)
        day = str(pickupDate.day)
        if len(day)<2:
            day = "0" + day
        typewrite(day)
        typewrite(str(pickupDate.year))
         
        click(569, 926)
         
        month = str(pickupDate.month)
        if len(month)<2:
            month = "0" + month
        typewrite(month)
        day = str(pickupDate.day)
        if len(day)<2:
            day = "0" + day
        typewrite(day)
        typewrite(str(pickupDate.year))
         
        click(695, 100)
         
        click(1542, 730)
         
        typewrite(str(driver.driver))
         
        press('enter')
        
        if str(driver.driver)[:3]!="801":
            click(1558,679)
            
            typewrite(driver.name)
         
            press('enter')
                
            sleep(0.5)    
            
            thru = False
            
            click(189, 854)
            hotkey('ctrl', 'a')
            hotkey('ctrl', 'c')
            clipTk=Tk()
            if "THRUWAY" in clipTk.clipboard_get():
                thru = True
                
            typewrite("TRUCK")
            press('tab')
            typewrite("0.55")
            press('tab')
            press('delete')
            press('tab')
            miles = "490"
            if str(driver.city)=="PACKER":
                miles = "507"
            if str(driver.city)=="NYCT":
                miles = "500"
            typewrite(miles)
            
            click(189, 890)
            hotkey('ctrl', 'a')
            hotkey('ctrl', 'c')
            if "THRUWAY" in clipTk.clipboard_get():
                thru = True
                
            click(189, 872)
            hotkey('ctrl', 'a')
            hotkey('ctrl', 'c')
            if "THRUWAY" in clipTk.clipboard_get():
                thru = True
            
            if thru:
                typewrite("COMPANY DR THRUWAY")
            
                press('tab')
            
                typewrite("1.00")
                press('tab')    
            
            
                press('delete')
                press('tab')
            
                if str(driver.city)=="PACKER":
                    typewrite("81.4")
                else:
                    typewrite("31.9")
                    
            else:
                press('delete')
                press('tab')
                press('delete')
                press('tab')
                press('delete')
                press('tab')
                press('delete')
            
            click(189, 890)
            hotkey('ctrl', 'a')
            hotkey('ctrl', 'c')
            if "THRUWAY" in clipTk.clipboard_get():
                thru = True
            clipTk.destroy()
            if thru:
                press('delete')
                press('tab')
                press('delete')
                press('tab')
                press('delete')
                press('tab')
                press('delete')
            
        if GetKeyState(145) < 0:
            exit()    
        
        sleep(2)
        
        click(1857, 120)
        click(1857, 120)
        
        sleep(3)
        
        click(1845, 200, button="right")
        
        sleep(1)
        
        click(1826, 312)
        
        sleep(0.3)
        
#         click(1600, 316)
#         
#         sleep(7)
        click(1600, 361)
        sleep(0.3)
        click(1772, 160)
             
#         sleep(5)
#         sleep(5)
        done=False
        while not done:
            try:
                if os.path.isfile(r"C:\Program Files\Microsoft Office 15\root\office15\outlook.exe"):
                    app = Application(backend="win32").connect(path = r"C:\Program Files\Microsoft Office 15\root\office15\outlook.exe")
                elif os.path.isfile(r"C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE"):
                    app = Application(backend="win32").connect(path = r"C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE")
                elif os.path.isfile(r"C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"):
                    app = Application(backend="win32").connect(path = r"C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE")
    
#                 elif os.path.isfile(r"C:\Program Files\WindowsApps\Microsoft.Office.Desktop.Outlook_16040.10827.20138.0_x86__8wekyb3d8bbwe\Office16\outlook.exe"):
#                     app = Application(backend="win32").connect(path = r"C:\Program Files\WindowsApps\Microsoft.Office.Desktop.Outlook_16040.10827.20138.0_x86__8wekyb3d8bbwe\Office16\outlook.exe")    
                else:
                    directoryPath = "C:\Program Files\WindowsApps\\"
                    if os.path.isdir("C:\Program Files\WindowsApps\\"):
                        contents = os.listdir("C:\Program Files\WindowsApps\\")
                        outLookFolders=[]
                        for folder in contents:
                            if os.path.isdir("C:\Program Files\WindowsApps\\"+folder):
                                if "outlook" in folder.lower():
                                    outLookFolders.append(folder)
                    outlookPath = ""
                    for folder in outLookFolders:
                        contents = os.listdir("C:\Program Files\WindowsApps\\"+folder)
                        for officeFolder in contents:
                            if os.path.isdir(directoryPath+folder+"\\"+officeFolder):
                                if "office" in officeFolder.lower():
                                    contentsInner = os.listdir(directoryPath+folder+"\\"+officeFolder)
                                    for outlookProgram in contentsInner:
                                        if outlookProgram.lower()=="outlook.exe":
                                            outlookPath=directoryPath+folder+"\\"+officeFolder+"\\"+outlookProgram
                    if os.path.isfile(outlookPath):
                        app = Application(backend="win32").connect(path = outlookPath)
                    else:    
                        popUpOK("Could not find Outlook in \"C:\Program Files\Microsoft Office 15\root\office15\outlook.exe\" \n or \"C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE\" \n or \"C:\Program Files (x86)\Microsoft Office\Office14\" \n or the \"C:\Program Files\WindowsApps\\\" folder")
                        exit()
                done=True
            except:
                pass
#             top_windows = []
#             EnumWindows(windowEnumerationHandler, top_windows)
#             for i in top_windows:
#                 if 'Dispatch-Mate' in i[1]:
#                     SetWindowPos(i[0], None, 0, 0, 1920, 1080, SWP_SHOWWINDOW)
#                     SetForegroundWindow(i[0])
                  
        winChildren = ""
            
        done = False
        
        while not done:
            dialogs = app.windows()
            topWindow = None
            for x in dialogs:
                if isinstance(handleprops.text(x), str) and not handleprops.text(x)==None:
                    try:
                        if "Carrier Confirmation" in handleprops.text(x):
                            winChildren = handleprops.children(x)
                            topWindow = x
                            break
                    except:
                        pass
                
            send = ""
            if topWindow==None:
                continue
                
            topWindowWrap = app.window(handle=topWindow)
            
            for x in winChildren:
#                 print(handleprops.text(x) + "   " + handleprops.classname(x))
                if handleprops.text(x)=="&Send":
                    send = x
                    done = True
#                 if handleprops.text(x)=="Fro&m":
#                     buttonWrap = topWindowWrap.child_window(handle=x).wrapper_object()
#                     buttonWrap.click()
#                     
                    
#                     
#                     if not clickTuple:
#                         moveTo(114, 221)
#                          
#                         while not GetKeyState(145)<0:
#                             True
#                          
#                         clickTuple = position()
#                      
# #                         else:                        
#                     click(clickTuple)
            
            if done==True:            
                buttonWrap = topWindowWrap.child_window(handle=send).wrapper_object()
                buttonWrap.click()
                
        
            
            
          
#             winChildren = handleprops.children(topWindow)
#               
#             for x in winChildren:
# #                 print(handleprops.text(x) + "   " + handleprops.classname(x))
#                 if handleprops.classname(x)=="NetUIHWND":
#                     topWindowWrap = app.window(handle=topWindow)
#                     netWrap = topWindowWrap.child_window(handle=x).wrapper_object()
#                     print(netWrap.Texts())
#               
#                     for y in handleprops.children(x):
#                         print(handleprops.text(y)) 
#       
#             app.top_window().window(title="From", control_type="Button").print_control_identifiers()
        
#             if not clickTuple:
#                 
#                 moveTo(113, 167)
#                 
#                 while not GetKeyState(13)<0:
#                     True
#                 
#                 clickTuple = position()
#                 
#             else:
#                 sleep(5)
#                 click((113, 167))
#                 
#             click(clickTuple)
        sleep(4)