Exemple #1
0
    def __login_central(self):
        import sys
        import os
        import urllib
        import urllib3
        import requests
        from yazaki_packages.logs import Logging
        resp = False
        try:
            # login yazaki website.
            url = f"https://{os.getenv('YAZAKI_HOST')}:{os.getenv('YAZAKI_PORT')}/cehttp/servlet/MailboxServlet"
            passwd = urllib.parse.quote(os.getenv('WHS_YAZAKI_PASSWD'))
            payload = f"operation=LOGON&remote={os.getenv('WHS_YAZAKI_USER')}&password={passwd}"
            headers = {'Content-Type': "application/x-www-form-urlencoded"}
            urllib3.disable_warnings()
            resp = requests.request("POST",
                                    url,
                                    data=payload,
                                    headers=headers,
                                    verify=False,
                                    timeout=3)
            print(f"{os.getenv('WHS_YAZAKI_USER')} => login success")
            Logging({os.getenv('WHS_YAZAKI_USER')},
                    f"{os.getenv('WHS_YAZAKI_USER')} login", "success")

        except Exception as msg:
            Logging({os.getenv('WHS_YAZAKI_USER')},
                    f"{os.getenv('WHS_YAZAKI_USER')} login",
                    'error: ' + str(msg))
            sys.exit(0)

        return resp
Exemple #2
0
    def download(self, currentdate, objtype, filename, filelink):
        from datetime import datetime
        import requests
        from bs4 import BeautifulSoup
        from termcolor import colored
        from yazaki_packages.logs import Logging
        import os

        session = self.__login()

        docs = False
        try:
            if session is not None:
                if session.status_code == 200:
                    # download file
                    rq = requests.get(filelink,
                                      stream=True,
                                      verify=False,
                                      cookies=session.cookies,
                                      allow_redirects=True)
                    docs = BeautifulSoup(rq.content, 'lxml')
                    print(
                        colored(
                            f"download gedi {objtype} file : {(filename).upper()}",
                            "blue"))
                    Logging(
                        os.getenv('YAZAKI_USER'),
                        f"download {objtype} file : {(filename).upper()} upload_at: {str(currentdate)}",
                        "success")
                    # logout
                    self.__logout(session)

        except Exception as ex:
            Logging(os.getenv('YAZAKI_USER'),
                    f"download {objtype} file : {(filename).upper()}",
                    'error: ' + str(ex))
            pass

        return docs
Exemple #3
0
    def __logout(self, session):
        import requests
        import os
        from yazaki_packages.logs import Logging

        url = f"https://{os.getenv('YAZAKI_HOST')}:{os.getenv('YAZAKI_PORT')}/cehttp/servlet/MailboxServlet?operation=LOGOFF"
        headers = {}
        pyload = {}
        requests.request("POST",
                         url,
                         data=pyload,
                         headers=headers,
                         verify=False,
                         timeout=3,
                         cookies=session.cookies)
        print(f"{os.getenv('YAZAKI_USER')} => logout success")
        Logging(os.getenv('YAZAKI_USER'), f"{os.getenv('YAZAKI_USER')} logout",
                "success")
        return True
Exemple #4
0
def __upload_to_spl_cloud():
    # check data on floder
    try:
        folder_target = cloud.check_folder("data")
        i = 0
        while i < len(folder_target):
            # show list file on folder_target
            yazaki_id = os.getenv('YAZAKI_USER')
            if folder_target[i] == "orderplan":
                yazaki_id = os.getenv('YAZAKI_USER')

            elif folder_target[i] == "receive":
                yazaki_id = os.getenv('YAZAKI_USER')

            else:
                yazaki_id = os.getenv('WHS_YAZAKI_USER')

            fname = f"{app_path}/data/{folder_target[i]}"
            folder_list = os.listdir(fname)
            if len(folder_list) > 0:
                line_doc = []
                token = cloud.get_token()
                if token != False:
                    x = 0
                    while x < len(folder_list):
                        # use text file only
                        r = folder_list[x]
                        print(r)
                        if r != ".gitkeep":
                            # upload text file spl cloud
                            txt_append = f"{fname}/{r}"
                            txt_name = (r[8:]).upper()
                            if txt_name[:1] == "N":
                                txt_name = (r[8:]).upper()

                            docs = {
                                'yazaki_id':
                                yazaki_id,
                                'gedi_type': (folder_target[i]).upper(),
                                'batch_id':
                                r[:7],
                                'file_name':
                                txt_name,
                                'file_path':
                                f"{app_path}/data/{folder_target[i]}/{r}",
                                'batch_size':
                                os.path.getsize(txt_append),
                                'upload_date':
                                datetime.now().strftime('%Y-%m-%d %X'),
                                'download':
                                0,
                                'is_type':
                                'U',
                                'token':
                                token,
                            }

                            # print(list(docs))

                            if cloud.upload_gedi_to_cloud(docs):
                                line_doc.append(len(line_doc))
                                # after upload remove text file
                                os.remove(txt_append)
                                print(
                                    colored(f"update data to spl cloud => {r}",
                                            "blue"))

                        x += 1

                    # notifies on line message
                    if len(line_doc) > 0:
                        msg = f"upload {(folder_target[i]).upper()}({len(line_doc)}) to XPW Online completed."
                        cloud.linenotify_error(msg)

                line_doc = []

            i += 1
    except Exception as ex:
        # cloud.linenotify_error(str(ex))
        Logging(f"UPLOAD", f"ERROR", str(ex))
        print(str(ex))
        pass
Exemple #5
0
import datetime
from yazaki_packages.logs import Logging
t = Logging("title", "description", "STATUS")

etd = str(
    (datetime.datetime.now() - datetime.timedelta(days=0)).strftime('%Y%m%d'))
print(etd)
Exemple #6
0
    def get_link(self):
        obj = []
        try:
            import datetime
            from datetime import timedelta
            import requests
            from bs4 import BeautifulSoup
            from termcolor import colored
            from yazaki_packages.logs import Logging
            import os

            etd = str((datetime.datetime.now() -
                       timedelta(days=7)).strftime('%Y%m%d'))

            # get cookies after login.
            session = self.__login()
            if session.status_code == 200:
                # get html page
                url = f"https://{os.getenv('YAZAKI_HOST')}:{os.getenv('YAZAKI_PORT')}/cehttp/servlet/MailboxServlet"
                headers = {'Content-Type': "application/x-www-form-urlencoded"}
                pyload = f"operation=DIRECTORY&fromdate={etd}&Submit=Receive"
                r = requests.request("POST",
                                     url,
                                     data=pyload,
                                     headers=headers,
                                     verify=False,
                                     timeout=3,
                                     cookies=session.cookies)
                # print(type(r))
                soup = BeautifulSoup(r.text, 'html.parser')
                for tr in soup.find_all('tr'):
                    found = False
                    i = 0
                    docs = []
                    for td in tr.find_all('td'):
                        txt = self.__restrip(td.text)
                        docs.append(txt)
                        if td.find("a") != None:
                            found = True

                        if found is True:
                            if len(docs) >= 9:
                                l = ObjectLink(
                                    os.getenv("YAZAKI_TYPE"), docs[0], docs[1],
                                    str(docs[2]).replace(",", "").strip(),
                                    docs[3], f"{docs[4]} {docs[5]}", docs[6],
                                    docs[7], docs[8], found)
                                obj.append(l)

                        i += 1

                # logout
                if len(obj) > 0:
                    print(colored(f"found new link => {len(obj)}", "green"))
                    Logging(os.getenv('YAZAKI_USER'),
                            f"{os.getenv('YAZAKI_USER')} get data {len(obj)}",
                            "success")

                self.__logout(session)

        except Exception as ex:
            Logging(os.getenv('YAZAKI_USER'),
                    f"{os.getenv('YAZAKI_USER')} get data",
                    'error: ' + str(ex))
            pass

        return obj