Esempio n. 1
0
def release(content, driver, account):
    transactionIndex = content.find("Transaction:")
    transaction = content[transactionIndex:content[transactionIndex:].
                          find("\n") + transactionIndex]
    ccnIndex = content.find("Cargo Control Number:")
    releaseIndex = content.find("Release Office: ")
    ccn = content[ccnIndex + 22:releaseIndex].strip()
    transaction = transaction + "\n" + content[ccnIndex:content[ccnIndex:].
                                               find("\n") + ccnIndex]
    deliveryIndex = content.find("Delivery Instructions") - 2

    containerIndex = content.find("Container ID(s):") + 17
    containers = []

    if containerIndex < deliveryIndex:
        while containerIndex < deliveryIndex:
            containers.append(
                content[containerIndex:content[containerIndex:].find(",") +
                        containerIndex].strip())
            containerIndex = content[containerIndex:].find(
                ",") + 1 + containerIndex
        print("\nReleasing the following containers: ")
        for cont in containers:
            sendRelease(cont, transaction, driver, account)
    else:
        m = Message(
            account=account,
            subject='CCN is Released: ' + ccn,
            body='PB #(if Seaport CCN): ' + ccn[-6:] +
            "\n\nThe RNS release message did not have a container number in it\n\n\nTHIS IS AN AUTOMATED MESSAGE, DO NOT REPLY",
            to_recipients=[
                Mailbox(email_address='*****@*****.**'),
            ])
        m.send()
        print("\nEmail with no container number")
Esempio n. 2
0
 def send_only_common_message(self, subject, body, to, cc):
     try:
         m = Message(account=self.exchangelib_connection,
                     folder=a.sent,
                     subject=subject,
                     body=body,
                     to_recipients=to,
                     cc_recipients=cc)
         m.send()
         print('Your message send success!')
     except Exception:
         print('Please try again!')
Esempio n. 3
0
def sendRelease(container, transaction, driver, account):
    print(container)
    driver.switch_to_default_content()
    driver.switch_to_frame(
        driver.find_element_by_css_selector("frame[src='topnavframe.asp']"))

    driver.find_element_by_css_selector(
        'a[href*="MenuNavFrame.asp?MenuID=5"').click()

    driver.switch_to_default_content()
    driver.switch_to_frame(
        driver.find_element_by_css_selector(
            "frame[src='MenuNavFrame.asp?MenuID=10']"))

    driver.find_element_by_css_selector(
        'a[href*="inventory/udsearch.asp"').click()

    failed = True
    while failed:
        try:
            driver.switch_to_default_content()
            driver.switch_to_frame(
                driver.find_element_by_css_selector(
                    "frame[src='portals/portal.asp']"))
            driver.switch_to_frame(
                driver.find_element_by_css_selector(
                    "frame[src='udSearchForm.asp?func=']"))
            failed = False
        except:
            pass

    elem = driver.find_element_by_name("unitprefix")
    elem.clear()
    elem.send_keys(container[:4])
    elem = driver.find_element_by_name("unitnumber")
    elem.clear()
    elem.send_keys(container[4:11])

    driver.find_element_by_css_selector(
        "Input[class='Button'][name='Submit']").click()

    #     driver.switch_to_default_content()
    #     driver.switch_to_frame(driver.find_element_by_css_selector("frame[src='portals/portal.asp']"))
    # #     frame = driver.find_element_by_css_selector("frame[src='udSearchResult.asp']")
    #     driver.switch_to_frame(driver.find_element_by_css_selector("frame[src='udSearchResult.asp']"))
    #     wait = WebDriverWait(driver, 10)
    #     wait.until(lambda driver: "Your query did not return any results" in driver.page_source or
    #                 EC.element_to_be_clickable(driver.find_element_by_css_selector("a[href*='unitDisposition.asp?eqid']")))
    found = False
    while not found:
        try:
            #             print(driver.page_source)
            driver.switch_to_default_content()
            driver.switch_to_frame(
                driver.find_element_by_css_selector(
                    "frame[src='portals/portal.asp']"))
            driver.switch_to_frame(
                driver.find_element_by_css_selector(
                    "frame[src='udSearchResult.asp']"))
            if ("Your query did not return any results" in driver.page_source):
                found = True
            driver.implicitly_wait(0)
            driver.find_element_by_css_selector(
                "a[href*='unitDisposition.asp?eqid']")
            found = True
            driver.implicitly_wait(60)
        except:
            driver.implicitly_wait(60)
    if ("Your query did not return any results" in driver.page_source):
        driver.switch_to_default_content()
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='topnavframe.asp']"))
        driver.find_element_by_css_selector(
            'a[href*="MenuNavFrame.asp?MenuID=1"').click()
        driver.switch_to_default_content()
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='MenuNavFrame.asp?MenuID=10']"))
        driver.find_element_by_css_selector(
            "a[href='Gate/VirtualArrive/VirtualArriveSearch.asp']").click()

        driver.switch_to_default_content()
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='portals/portal.asp']"))
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='VirtualArriveForm.asp']"))
        driver.find_element_by_id("1").send_keys(container[:4])
        driver.find_element_by_id("2").send_keys(container[4:11])
        driver.find_element_by_css_selector(
            "Input[class='Button'][name='Submit']").click()

        found = False
        while not found:
            try:
                driver.switch_to_default_content()
                driver.switch_to_frame(
                    driver.find_element_by_css_selector(
                        "frame[src='portals/portal.asp']"))
                driver.switch_to_frame(
                    driver.find_element_by_css_selector(
                        "frame[src='VirtualArriveResult.asp']"))
                if ("Your query did not return any results"
                        in driver.page_source):
                    found = True
                driver.implicitly_wait(0)
                driver.find_element_by_css_selector(
                    "a[href*='javascript:EditVirtualArrive(']")
                found = True
                driver.implicitly_wait(60)
            except:
                driver.implicitly_wait(60)

        if (not "Your query did not return any results" in driver.page_source):
            driver.find_element_by_css_selector(
                "a[href*='javascript:EditVirtualArrive(']").click()

            parentWindow = driver.current_window_handle
            handles = driver.window_handles
            for windowHandle in handles:
                if (not windowHandle == parentWindow):
                    driver.switch_to.window(windowHandle)
                    elem = driver.find_element_by_id("CkbCR")
                    #                 try:
                    # eqcomments
                    if (elem.get_attribute("checked") == "true"):
                        driver.find_element_by_id("CkbCR").click()
                        driver.find_element_by_name("eqcomments").send_keys(
                            "\n" + transaction)

                        elem = driver.find_element_by_name("bkg_nbr_dof")
                        if (elem.get_attribute("value") == ""):
                            elem.send_keys("import")
                        elem1 = Select(driver.find_element_by_name("Line"))
                        elem2 = Select(driver.find_element_by_name("lineid"))
                        try:
                            if (elem1.first_selected_option.text == ""):
                                elem1.select_by_visible_text(
                                    elem2.first_selected_option.text)
                        except:
                            elem1.select_by_visible_text(
                                elem2.first_selected_option.text)
                        if driver.find_element_by_name(
                                "cargo_weight").get_attribute("value") == "":
                            driver.find_element_by_name(
                                "cargo_weight").send_keys("0")
                        Select(driver.find_element_by_name(
                            "ddWeightUnits")).select_by_visible_text("Kgs")
                        driver.find_element_by_css_selector(
                            "Input[class='Button'][name='Submit']").click()
                        wait = WebDriverWait(driver, 10)
                        wait.until(
                            lambda driver: "Your information has been saved."
                            in driver.page_source)

                    driver.close()
                    driver.switch_to.window(parentWindow)
    else:
        driver.find_element_by_css_selector(
            "a[href*='unitDisposition.asp?eqid']").click()
        driver.switch_to_default_content()
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='portals/portal.asp']"))
        elem = driver.find_element_by_css_selector(
            "input[name='crelease'][value='1']")
        if elem.get_attribute("checked") != "true":
            elem.click()
            driver.find_element_by_name("comments").send_keys("\n" +
                                                              transaction)
            driver.find_element_by_css_selector(
                "Input[class='Button'][name='Submit']").click()

        if driver.find_element_by_css_selector(
                "input[name='lfd']").get_attribute("value") == "":
            m = Message(
                account=account,
                subject='Missing LFD for container: ' + container,
                body='Missing LFD for container: ' + container +
                "\n\n\nTHIS IS AN AUTOMATED MESSAGE, DO NOT REPLY",
                to_recipients=[
                    Mailbox(email_address='*****@*****.**'),
                    Mailbox(email_address='*****@*****.**'),
                ])
            m.send()

    return True
Esempio n. 4
0
def sendRelease(container, driver, account):
    success = True
    print(container)
    driver.switch_to_default_content()
    driver.switch_to_frame(
        driver.find_element_by_css_selector("frame[src='topnavframe.asp']"))

    driver.find_element_by_css_selector(
        'a[href*="MenuNavFrame.asp?MenuID=5"').click()

    driver.switch_to_default_content()
    driver.switch_to_frame(
        driver.find_element_by_css_selector(
            "frame[src='MenuNavFrame.asp?MenuID=10']"))

    driver.find_element_by_css_selector(
        'a[href*="inventory/udsearch.asp"').click()

    failed = True
    while failed:
        try:
            driver.switch_to_default_content()
            driver.switch_to_frame(
                driver.find_element_by_css_selector(
                    "frame[src='portals/portal.asp']"))
            driver.switch_to_frame(
                driver.find_element_by_css_selector(
                    "frame[src='udSearchForm.asp?func=']"))
            failed = False
        except:
            pass

    elem = driver.find_element_by_name("unitprefix")
    elem.clear()
    elem.send_keys(container[:4])
    elem = driver.find_element_by_name("unitnumber")
    elem.clear()
    elem.send_keys(container[4:11])

    driver.find_element_by_css_selector(
        "Input[class='Button'][name='Submit']").click()

    #     driver.switch_to_default_content()
    #     driver.switch_to_frame(driver.find_element_by_css_selector("frame[src='portals/portal.asp']"))
    # #     frame = driver.find_element_by_css_selector("frame[src='udSearchResult.asp']")
    #     driver.switch_to_frame(driver.find_element_by_css_selector("frame[src='udSearchResult.asp']"))
    #     wait = WebDriverWait(driver, 10)
    #     wait.until(lambda driver: "Your query did not return any results" in driver.page_source or
    #                 EC.element_to_be_clickable(driver.find_element_by_css_selector("a[href*='unitDisposition.asp?eqid']")))
    found = False
    while not found:
        try:
            #             print(driver.page_source)
            driver.switch_to_default_content()
            driver.switch_to_frame(
                driver.find_element_by_css_selector(
                    "frame[src='portals/portal.asp']"))
            driver.switch_to_frame(
                driver.find_element_by_css_selector(
                    "frame[src='udSearchResult.asp']"))
            if ("Your query did not return any results" in driver.page_source):
                found = True
            driver.implicitly_wait(0)
            driver.find_element_by_css_selector(
                "a[href*='unitDisposition.asp?eqid']")
            found = True
            driver.implicitly_wait(60)
        except:
            driver.implicitly_wait(60)
    if ("Your query did not return any results" in driver.page_source):
        driver.switch_to_default_content()
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='topnavframe.asp']"))
        driver.find_element_by_css_selector(
            'a[href*="MenuNavFrame.asp?MenuID=1"').click()
        driver.switch_to_default_content()
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='MenuNavFrame.asp?MenuID=10']"))
        driver.find_element_by_css_selector(
            "a[href='Gate/VirtualArrive/VirtualArriveSearch.asp']").click()

        driver.switch_to_default_content()
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='portals/portal.asp']"))
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='VirtualArriveForm.asp']"))
        driver.find_element_by_id("1").send_keys(container[:4])
        driver.find_element_by_id("2").send_keys(container[4:11])
        driver.find_element_by_css_selector(
            "Input[class='Button'][name='Submit']").click()

        found = False
        while not found:
            try:
                driver.switch_to_default_content()
                driver.switch_to_frame(
                    driver.find_element_by_css_selector(
                        "frame[src='portals/portal.asp']"))
                driver.switch_to_frame(
                    driver.find_element_by_css_selector(
                        "frame[src='VirtualArriveResult.asp']"))
                if ("Your query did not return any results"
                        in driver.page_source):
                    found = True
                driver.implicitly_wait(0)
                driver.find_element_by_css_selector(
                    "a[href*='javascript:EditVirtualArrive(']")
                found = True
                driver.implicitly_wait(60)
            except:
                driver.implicitly_wait(60)

        if (not "Your query did not return any results" in driver.page_source):
            driver.find_element_by_css_selector(
                "a[href*='javascript:EditVirtualArrive(']").click()

            parentWindow = driver.current_window_handle
            handles = driver.window_handles
            for windowHandle in handles:
                if (not windowHandle == parentWindow):
                    driver.switch_to.window(windowHandle)
                    if (driver.find_element_by_id("CkbFR").get_attribute(
                            "checked") == "true"):
                        driver.find_element_by_id("CkbFR").click()
                        driver.find_element_by_css_selector(
                            "Input[class='Button'][name='Submit']").click()
                        wait = WebDriverWait(driver, 10)
                        wait.until(
                            lambda driver: "Your information has been saved."
                            in driver.page_source)

                    driver.close()
                    driver.switch_to.window(parentWindow)
        else:
            print(container + " NOT IN SYSTEM")
            success = False

    else:
        driver.find_element_by_css_selector(
            "a[href*='unitDisposition.asp?eqid']").click()
        driver.switch_to_default_content()
        driver.switch_to_frame(
            driver.find_element_by_css_selector(
                "frame[src='portals/portal.asp']"))
        elem = driver.find_element_by_css_selector(
            "input[name='frelease'][value='1']")
        if elem.get_attribute("checked") != "true":
            elem.click()
            #             driver.find_element_by_name("comments").send_keys("\n"+transaction)
            driver.find_element_by_css_selector(
                "Input[class='Button'][name='Submit']").click()

        if driver.find_element_by_css_selector(
                "input[name='lfd']").get_attribute("value") == "":
            m = Message(
                account=account,
                subject='Missing LFD for container: ' + container,
                body='Missing LFD for container: ' + container,
                to_recipients=[Mailbox(email_address='*****@*****.**')])
            m.send()

    return success