Jump to content

Hassett Recv 2.0


Recommended Posts

So I'm trying to build this simple script to help us at work to receive a bunch of container ID's. 
The problem is the program we use sucks, and is functionally inefficient, so i'm trying to automate some things.

What I need to do:
 

  • Copy all the Hassett container ID's to the clipboard ( essentially selecting everything on the screen, and copy it to clipboard )
  • Then I need to parse all the container ID's from the clipboard string
  • Then write each container ID to a box in the program at work, and press enter.

 

Problem:

I can parse all the container ID's from the clipboard string, but it is not the correct length.


Example:

 

EWRSEA98195198494   EWRSEA98195192948

hf98h234f               f0j32jfdsijf9823j

    ATLSEA89464684894   f8h3298hf23

            f23098fh                DFWSEA98464548455

My script looks for the origin ( EWR, ATL, DFW, etc.. ), which works fine, but then I need to StringMid from the beginning of that location, then +17 to get the whole string. It's not working correctly and only giving me the origin. Each container ID ( DFWSEA98464548455 ) is a static length of 17 characters and always contains SEA.

Code:

#Include <Array.au3>

#Region HOTKEY
HotKeySet('{INSERT}', 'INPUT_CONTAINER')
#EndRegion

#Region Variables
Global $STATIC_DC = ['ATL', 'RDU', 'MCO', 'MEM' & _
                     '', 'BWI', 'PHX', 'BOS', 'STL' & _
                     '', 'CVG', 'EWR', 'DFW', 'ORD' & _
                     '', 'DEN', 'SLC', 'LAX', 'SFO' & _
                     '', 'SEA']

Global $ORIGIN = ['']
Global $DEST = ['']
#EndRegion

#Region Functions
Func INPUT_CONTAINER()
    Local $ORIGIN = ['EWR']
    Local $DEST = ['SEA']
    Local $CONTAINER = StringStripWS(ClipGet(), 8)
    Local $CONTAINER_LENGTH = StringLen($CONTAINER)
    ;MsgBox(0, 'Test', $CONTAINER)

    For $i = 1 To $CONTAINER_LENGTH
        $STEP_STRING = StringMid($CONTAINER, $i, 3)
        For $ii = 0 To UBound($STATIC_DC) -1
        If StringStripWS($STATIC_DC[$ii], 8) = $STEP_STRING Then
            $CONTAINER_STRING = StringMid($STEP_STRING, 1, 17)
            MsgBox(0, 'Test', $CONTAINER_STRING)
            ;MsgBox(0, 'Test', 'Container Found. ' & $STATIC_DC[$0])
        EndIf
        ;MsgBox(0, 'Test', $STATIC_DC[$i])
        Next
        ;MsgBox(0, 'Test', $CONTAINER_STRING)
    Next
EndFunc


 

$CONTAINER_STRING = StringMid($STEP_STRING, 1, 17)

This part is supposed to give me the whole Container ID string, but instead it only gives me the origin ( DFW, ATL, EWR, etc... )

Edited by FengHuangWuShen
Link to comment
Share on other sites

You can easily build an array of identifiers since they have a fixed pattern. I guess that the first three characters are always uppercase letters in [A-Z] and that the last 11 are always digits. If there is something missing or wrong, just chime. Note that none of the three wrongly formatted ID near the end are correctly ignored.

Local $s = _
"EWRSEA98195198494   EWRSEA98195192948" & @CRLF & _
"" & @CRLF & _
"hf98h234f               f0j32jfdsijf9823j" & @CRLF & _
"" & @CRLF & _
"    ATLSEA89464684894   f8h3298hf23" & @CRLF & _
"ATLSE597048044051         A45SEA87946168456   ZZZSEA01234X56789" & @CRLF & _
"            f23098fh                DFWSEA98464548455"

Local $aID = StringRegExp($s, "(?m)([A-Z]{3}SEA\d{11})", 3)
_ArrayDisplay($aID)

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Yes, that's correct. The entire string always has uppercase letters, the numeric for the last part.

I was thinking about StringRegExp as well, but I'm unfamiliar with how to construct those... such as (?m), what does it mean? and the \d.

I'm going to assume {3} is the length in which to look for the first three characters, and the the {11} is the remaining numerical characters.

 

#Include <Array.au3>

#Region HOTKEY
HotKeySet('{INSERT}', 'INPUT_CONTAINER')
#EndRegion

#Region Reference
Global $STATIC_DC = ['ATL', 'RDU', 'MCO', 'MEM' & _
                     '', 'BWI', 'PHX', 'BOS', 'STL' & _
                     '', 'CVG', 'EWR', 'DFW', 'ORD' & _
                     '', 'DEN', 'SLC', 'LAX', 'SFO' & _
                     '', 'SEA']

#EndRegion

#Region Functions
Func INPUT_CONTAINER()
    Local $CONTAINER_STRING = StringStripWS(ClipGet(), 8) & 'ZZZSEA01234X56789'

    Local $CONTAINER_LIST = StringRegExp($CONTAINER_STRING, "(?m)([A-Z]{3}SEA\d{11})", 3)

    For $i = 0 To UBound($CONTAINER_LIST) - 1
        MsgBox(0, 'Test', $CONTAINER_LIST[$i])
    Next
EndFunc
#EndRegion

While 1
Sleep(10)
WEnd

I got it working as I need now, thank you. This code will find and display each container from the CONTAINER_LIST, then I can do the action next.

Link to comment
Share on other sites

The multiline option (?m) isn't really necessary since there is no need for anchor(s), hence you can leave it out. Also you don't need to use StringStripWS() prior to filtering by regexp.

{value} used are repetition factors and \d stands for "decimal digit". There is a short presentation of pattern elements in the help file under StringRegExp; it briefly discusses almost all non-cryptic features of PCRE (the regexp engine AutoIt uses).

Glad it works for your needs.

EDIT: forgot to mention something.

If you have an exhaustive list of all the possible alpha prefixes (before "SEA") then you can be even more strict about what the regexp will accept.

For instance:

Local $CONTAINER_LIST = StringRegExp($CONTAINER_STRING, "((?:ABC|DEF|XYZ)SEA\d{11})", 3)

will only find IDs starting with ABCSEA or DEFSEA or XYZSEA and no other.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Okay, thanks for the explanation. I haven't used autoit in awhile :P

Yea, even the values before SEA are static, that's why I had the array with STATIC_DC:

 

Global $STATIC_DC = ['ATL', 'RDU', 'MCO', 'MEM' & _
                     '', 'BWI', 'PHX', 'BOS', 'STL' & _
                     '', 'CVG', 'EWR', 'DFW', 'ORD' & _
                     '', 'DEN', 'SLC', 'LAX', 'SFO' & _
                     '', 'SEA']

But there are also some others too, like 99M.... without SEA, and then a bunch of numbers after it. But that is for another part of the program.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...