Exemplo n.º 1
0
def interparse(inpath, infile, imfile):

    error = 1

    today = datetime.datetime.today()
    year = str(today.year)
    month = str(today.month)
    day = str(today.day)
    datestr = month + '/' + day + '/' + year

    pyr = year[2] + year[3]
    # print(pyr)

    date_stdtxt1 = re.compile(
        r'(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s?\d{1,2},?\s?\d{4}'
    )
    date_stdtxt2 = re.compile(
        r'(?:January|February|March|April|June|July|August|September|October|November|December)\s?\d{1,2},?\s?\d{4}'
    )
    date_y2 = re.compile(
        r'(?:0[1-9]|[12][0-9]|3[01])[/](?:0[1-9]|[12][0-9]|3[01])[/]\d{2}')
    date_y4 = re.compile(
        r'(?:0[1-9]|[12][0-9]|3[01])[/](?:0[1-9]|[12][0-9]|3[01])[/]\d{4}')
    date_ny4 = re.compile(r'\d{4}-\d{2}-\d{2}')
    date_mil2 = re.compile(
        r'\d{1,2}\s?(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s?\d{2}'
    )
    date_mil4 = re.compile(
        r'\d{1,2}\s?(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s?\d{4}'
    )
    date_y2mdns = re.compile(r'\s' + pyr +
                             '(?:0[1-9]|1[012])(?:0[1-9]|[12][0-9]|3[01])')
    date_int = re.compile(
        r'\d{1,2}\s?(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\s?\d{4}'
    )
    car_year = re.compile(r'(?:19|20)\d{2}')

    container_p = re.compile(r'[A-Za-z]{4}\s?[Ool0123456789]{7}')
    container_p2 = re.compile(
        r'[A-Za-z]{4}\s?[Ool0123456789]{6}\s[Ool0123456789]')
    container_p3 = re.compile(
        r'[A-Za-z]{4}\s?[Ool0123456789]{6}-[Ool0123456789]')
    book1 = re.compile(r'[A-Z0-9]{10}')
    book2 = re.compile(r'[A-Z0-9]{11}')
    book3 = re.compile(r'[A-Z0-9]{12}')
    bol1 = re.compile(r'\d{8}')
    bol2 = re.compile(r'[A-Z][0-9]{5}')
    bol3 = re.compile(r'[Ool0123456789]{7}')
    order_p = re.compile(r'[Ool0123456789]{6}')
    time_p24 = re.compile(
        r'(?:[1-9]|0[1-9]|1[0-9]|2[01234])[:](?:0[0-9]|[12345][0-9])')
    vin_p = re.compile(r'[Ool0123456789]{11}')

    longs = open(inpath + infile).read()
    ss = longs.lower()

    typedef = 'Empty Out'
    if 'empty in' in ss:
        typedef = 'Empty In'
    elif 'load in' in ss:
        typedef = 'Load In'
    elif 'load out' in ss:
        typedef = 'Load Out'

    tdate = datetime.datetime.strptime(datestr,
                                       '%m/%d/%Y').strftime('%Y/%m/%d')
    thistime = '00:01'
    container = 'NFI'

    ilist = [
        'TRUCK NUMBER', 'Chassis', 'Release', 'Seals', 'GROSS WT', 'CARGO WT',
        'SIZE/Type'
    ]
    obj = {}
    for i in ilist:
        obj.update({i: 'NFI'})
        match = re.search(i + ':?\s?\s?(\w*)', longs)
        if match:
            test = match.group(1)
            if len(test) > 0:
                nratio = len(re.sub("\D", "", test)) / len(test)
                if nratio > .4:
                    obj.update({i: test})

    datef = date_int.findall(longs)
    dateg = date_ny4.findall(longs)
    print('dateg=', dateg)
    if datef:
        fix = re.sub(" ", "", datef[0])
        try:
            tdate = datetime.datetime.strptime(fix,
                                               '%d%b%Y').strftime('%Y/%m/%d')
        except:
            err = 1
    if dateg:
        fix = re.sub(" ", "", dateg[0])
        if 1 == 1:  # try:
            tdate = datetime.datetime.strptime(fix,
                                               '%Y-%m-%d').strftime('%Y/%m/%d')
            print('tdate=', tdate)
        if 1 == 2:  # except:
            err = 1

    timeat = time_p24.findall(longs)
    if timeat:
        thistime = timeat[0]

    t1 = container_p.findall(longs)
    t2 = container_p2.findall(longs)
    t3 = container_p3.findall(longs)
    t4 = t1 + t2 + t3
    if t4:
        fix = t4[0].strip()
        fix = fix.replace(' ', '')
        fix = fix.replace('-', '')
        back7 = fix[-7:]
        back7 = back7.replace('O', '0')
        back7 = back7.replace('o', '0')
        back7 = back7.replace('l', '1')
        front4 = fix[0] + fix[1] + fix[2] + fix[3]
        container = front4.upper() + back7
        print(container)

    # Search for things that are the keywords:
    driverlist = ['Ghanem', 'Davis', 'Alameh', 'Tibbs', 'Khoder']
    obj.update({'Driver': 'NFI'})
    for i in driverlist:
        match = re.search(i.lower(), ss)
        if match:
            obj.update({'Driver': i})

    print(obj)

    if tdate is not None:
        thisdate = datetime.datetime.strptime(tdate, '%Y/%m/%d')
    else:
        thisdate = today

    chassis = obj.get("Chassis")
    if chassis == 'NFI':
        chassis = 'OWN'

    trucknum = obj.get("TRUCK NUMBER")
    if '87' in trucknum:
        driver = 'Hassan Khoder'
        trucknum = '870F36'
    else:
        driver = 'Darrell Tibbs'

    idat = Interchange.query.filter(Interchange.Original == imfile).first()
    if idat is None:
        # Check to see if this file is in database already
        input = Interchange(Container=container,
                            TruckNumber=trucknum,
                            Driver=driver,
                            Chassis=chassis,
                            Date=thisdate,
                            Release=obj.get("Release"),
                            GrossWt=obj.get("GROSS WT"),
                            Seals=obj.get("Seals"),
                            ConType=obj.get("SIZE/Type"),
                            CargoWt=obj.get("CARGO WT"),
                            Time=thistime,
                            Status='AAAAAA',
                            Original=imfile,
                            Path='NFI',
                            Type=typedef,
                            Jo='NAY',
                            Company='NAY',
                            Other=None)
        # if missing is None:
        print('Data is being added to database: interchange')
        db.session.add(input)
        db.session.commit()
        error = 0
    else:
        print('This picture original found in database already: ', imfile)
        error = 0

    tunnel.stop()
    return error
Exemplo n.º 2
0
                selectElem.clear()
                selectElem.send_keys(bk)
                time.sleep(1)
                try:
                    selectElem2 = browser.find_element_by_xpath(
                        '/html/body/div[2]/main/form/div/div/div/div/div[1]/div/div/div[4]/button'
                    )
                    selectElem2.click()
                    time.sleep(10)
                    selectElem3 = browser.find_element_by_xpath(
                        '//*[@id="divTosInquiryResult"]/div/div/div[3]/div[2]/table/tbody/tr/td[5]'
                    )
                    bgr = selectElem3.text
                    selectElem4 = browser.find_element_by_xpath(
                        '//*[@id="divTosInquiryResult"]/div/div/div[3]/div[2]/table/tbody/tr/td[8]'
                    )
                    cut = selectElem4.text
                except:
                    bgr = 'Unknown'
                    cut = 'Unknown'

            jdat.Time2 = bgr
            jdat.Time3 = cut
            db.session.commit()
            print(
                f'Output for Shipper {jdat.Shipper} with Export {jdat.Booking} has BGR {bgr} and Cutoff {cut}'
            )
            browser.quit()

tunnel.stop()
Exemplo n.º 3
0
def autofind(p5s, txtfile, srcfile):

    wt = None
    value = None
    fout = p5s + txtfile
    error = 1

    vinlist = vinfind(fout)
    nvins = len(vinlist)
    # print(vinlist)

    carrier, addr1, addr2, phone = carrierfind(fout)
    # print(carrier,addr1,addr2,phone)

    pudate, deldate, payment = orderinfo(fout)
    pufrom = comefrom(fout)
    # print(pudate,deldate,payment,pufrom)

    ncars, carlist = dispatchfind(fout)
    # print(nvins,ncars,len(carlist))

    try:
        date1 = datetime.datetime.strptime(pudate, "%m/%d/%Y")
    except:
        date1 = None
    try:
        date2 = datetime.datetime.strptime(deldate, "%m/%d/%Y")
    except:
        date2 = None

    payment = d2s(payment)
    try:
        total = float(payment)
        each = total / float(ncars)
        each = str(each)
        each = d2s(each)
    except:
        each = '0.00'

    adata = Autos.query.all()
    lauto = len(adata) - 1
    for j, adat in enumerate(adata):
        if j == lauto:
            thisid = adat.id
            nextid = thisid + 1

    newfile = 'DISP' + str(nextid) + '.pdf'
    original = 'tmp/vdispatch/' + newfile
    orderid = 'disp' + str(nextid)

    adat = Autos.query.filter(Autos.Orderid == orderid).first()
    if adat is None:
        print("This is a new tow order so we need to add it to the database")
        error = 0
        for car in carlist:
            # carlist.append([year,make,model,color,vin])
            vin = car[4]
            year = car[0]
            make = car[1]
            model = car[2]
            color = car[3]
            wt = '0'
            value = '0'
            if len(vin) == 17:
                try:
                    year, make, model, wt, value, navg = vinscraper(vin)
                    value = value.replace('$', '')
                except:
                    wt = 'Bad Vin'
                    value = 'Bad Vin'
            else:
                vin = 'NoVIN'

            bdat = Autos.query.filter(Autos.VIN == vin).first()
            if bdat is None or vin == 'NoVIN':
                print("Entering data in Autos database")
                input = Autos(Jo=orderid,
                              Hjo=None,
                              Year=year,
                              Make=make,
                              Model=model,
                              Color=color,
                              VIN=vin,
                              Title=None,
                              State=None,
                              EmpWeight=wt,
                              Dispatched='Horizon Motors',
                              Value=value,
                              TowCompany=carrier,
                              TowCost=payment,
                              TowCostEa=each,
                              Original=original,
                              Status='New',
                              Date1=date1,
                              Date2=date2,
                              Pufrom=pufrom,
                              Delto='FEL',
                              Ncars=ncars,
                              Orderid=orderid)
                db.session.add(input)
                db.session.commit()
                print('This auto not in database, adding to records...')
                print(orderid, year, make, model, color, vin, wt, value,
                      carrier, payment, each, ncars, pufrom, original)
                print(' ')
            else:
                print('This auto already in the database')
                print('Modifying and updating records...')
                print(orderid, year, make, model, color, vin, wt, value,
                      carrier, payment, each, ncars, pufrom, original)
                print(' ')
                bdat.EmpWeight = wt
                bdat.Value = value
                bdat.TowCompany = carrier
                bdat.TowCost = payment
                bdat.TowCostEa = each
                bdat.Ncars = ncars
                bdat.Pufrom = pufrom
                bdat.Delto = 'FEL'
                db.session.commit()

            pdat = People.query.filter((People.Ptype == 'TowCo')
                                       & (People.Company == carrier)).first()
            if pdat is None:
                input = People(Company=carrier,
                               First='',
                               Middle='',
                               Last='',
                               Addr1=addr1,
                               Addr2=addr2,
                               Addr3='',
                               Idtype='',
                               Idnumber='',
                               Telephone=phone,
                               Email='',
                               Associate1='',
                               Associate2='',
                               Date1=today,
                               Date2=None,
                               Original='',
                               Ptype='TowCo',
                               Temp1='',
                               Temp2='')
                db.session.add(input)
                db.session.commit()
    tunnel.stop()
    return newfile, error