Jump to content
fmendi

Autofill Paypal Shipping Address --- Help

Recommended Posts

Hi, I hadn't posted in such  long time that my profile was deleted so I re-subscribed as fmendi...

Anyway, I'm sure there are members here that use the PayPal shipping service to print out labels which requires copying and pasting each element of the recipient's address into the different fields .

https://www.paypal.com/shiplabel/create

For example, copy the following into clipboard and using the following script works well except for a few things...

Frank Conte
2133 Elm St.
Gainesville FL, 45679.

$_full_add = ClipGet()  ; places copied full address into ClipGet
   $_last_line = StringRegExp($_full_add, "(?si)^.*\n(.*)$", 1) ;Last line of address
   $_name = StringRegExp($_full_add, "\A.*", 1) ;First line - full name
   $_add = StringRegExp($_full_add, "(?:\r\n?|\n)(.+)", 1)
   $_city = StringRegExp($_last_line[0], "^[^\s]+", 1) ;First word of last line
   $_state = StringRegExp($_last_line[0], "\s+[^\s]+", 1); Second last word in line
   $_zip = StringRegExp($_full_add, ".*([0-9]{5})", 1) ;Last full "word"
    
MsgBox(1, "",  $_zip[0])
MsgBox(1, "",  $_state[0])
MsgBox(1, "",  $_city[0])
MsgBox(1, "",  $_add[0])

 

1. If there is more than one word in the city's name (eg New York), only the first word is captured and the zip code becomes the second word

2. If State is followed by a comma,  $_zip will also include the comma

3. If the address is given in one line only, the script falls apart  eg Frank Conte 2133 Elm St. Gainesville FL, 45679.

4. God knows what other variations of the address may fail

 

My experience with StringRegExp is limited to say the least, any help would be appreciated.

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

fmendi,

We do not delete accounts unless asked - there is an "fmen" account still up and running which I presume is yours. But feel free to stick with this new one.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Here a first draft.  If you find new format of address, include them in the array, we will see how we can solve it.

#include <Constants.au3>
#include <Array.au3>

Local $aAddr = [ _
  "Frank Conte 2133 Elm St. Gainesville FL, 45679.", _
  "Frank F. Conte" & @CRLF & "123 First Rd." & @CRLF & "New York NY, 12345." ]

Local $aComp

For $sAddr in $aAddr
  $aComp = StringRegExp($sAddr, "(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)", 1)
  _ArrayDisplay($aComp)
Next

 

Edited by Nine
Extract state also...

Share this post


Link to post
Share on other sites

Awesome work, Nine. I don't think I'd have ever come up with such the elegant regex such as:  

(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)

Two further questions will really expose my ignorance to both regex and arrays...

1. The results place  City and State into one element. I need those separated into individual elements but have no idea on how.

2. How can I extract the 5 different elements from the array into  variables to be able to paste them into the PayPal form?

I'm looking at _ArrayToClip() and_ArrayToString() with little success.

Thank you for the help....

Share this post


Link to post
Share on other sites
23 minutes ago, fmendi said:

1. The results place  City and State into one element. I need those separated into individual elements but have no idea on how.

Not in my case :

image.png.4741989bcac9d7f6c9b57a1df573e78f.pngimage.png.7bd91a871a32207e26111911fb37c963.png

23 minutes ago, fmendi said:

2. How can I extract the 5 different elements from the array into  variables to be able to paste them into the PayPal form?

There is no need to transfer (extract) the content of the array to variables. You can use them individually by using the index (0-based).

For example to get the name use $aComp[0], for city use $aComp[2], for zip $aComp[4], etc...

 

ps Make sure you got the latest code I posted, I made a small modif to extract state separately

Edited by Nine

Share this post


Link to post
Share on other sites
5 hours ago, fmendi said:

Hi, I hadn't posted in such  long time that my profile was deleted so I re-subscribed as fmendi...

Doubt that as we don't delete accounts unless requested. So what was your original account?

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I cannot thank you enough, Nine. Hopefully this will be useful for other members. Here's the full script...

Before running the script copy the full address into the clipboard and have the cursor focused on "Customer Name" in the Paypal shipping form.

Any improvements are welcome, of course.

;Autofill PayPal Shipping Page

#include <Constants.au3>
#include <Array.au3>
Local $aComp = clipGet()
Local $aAddr = [$aComp]

For $sAddr in $aAddr
  $aComp = StringRegExp($sAddr, "(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)", 1)
Next
If $aComp[3] = "AL" Then $aComp[3] ='Alabama'
If $aComp[3] = "AK" Then $aComp[3] ='Alaska'
If $aComp[3] = "AZ" Then $aComp[3] ='Arizona'
If $aComp[3] = "AR" Then $aComp[3] ='Arkansas'
If $aComp[3] = "CA" Then $aComp[3] ='California'
If $aComp[3] = "CO" Then $aComp[3] ='Colorado'
If $aComp[3] = "CT" Then $aComp[3] ='Connecticut'
If $aComp[3] = "DE" Then $aComp[3] ='Delaware'
If $aComp[3] = "DC" Then $aComp[3] ='District of Columbia'
If $aComp[3] = "FL" Then $aComp[3] ='Florida'
If $aComp[3] = "GA" Then $aComp[3] ='Georgia'
If $aComp[3] = "HI" Then $aComp[3] ='Hawaii'
If $aComp[3] = "ID" Then $aComp[3] ='Idaho'
If $aComp[3] = "IL" Then $aComp[3] ='Illinois'
If $aComp[3] = "IN" Then $aComp[3] ='Indiana'
If $aComp[3] = "IA" Then $aComp[3] ='Iowa'
If $aComp[3] = "KS" Then $aComp[3] ='Kansas'
If $aComp[3] = "KY" Then $aComp[3] ='Kentucky'
If $aComp[3] = "LA" Then $aComp[3] ='Louisiana'
If $aComp[3] = "ME" Then $aComp[3] ='Maine'
If $aComp[3] = "MD" Then $aComp[3] ='Maryland'
If $aComp[3] = "MA" Then $aComp[3] ='Massachusetts'
If $aComp[3] = "MI" Then $aComp[3] ='Michigan'
If $aComp[3] = "MN" Then $aComp[3] ='Minnesota'
If $aComp[3] = "MS" Then $aComp[3] ='Mississippi'
If $aComp[3] = "MO" Then $aComp[3] ='Missouri'
If $aComp[3] = "MT" Then $aComp[3] ='Montana'
If $aComp[3] = "NE" Then $aComp[3] ='Nebraska'
If $aComp[3] = "NV" Then $aComp[3] ='Nevada'
If $aComp[3] = "NH" Then $aComp[3] ='New Hampshire'
If $aComp[3] = "NJ" Then $aComp[3] ='New Jersey'
If $aComp[3] = "NM" Then $aComp[3] ='New Mexico'
If $aComp[3] = "NY" Then $aComp[3] ='New York'
If $aComp[3] = "NC" Then $aComp[3] ='North Carolina'
If $aComp[3] = "ND" Then $aComp[3] ='North Dakota'
If $aComp[3] = "OH" Then $aComp[3] ='Ohio'
If $aComp[3] = "OK" Then $aComp[3] ='Oklahoma'
If $aComp[3] = "OR" Then $aComp[3] ='Oregon'
If $aComp[3] = "PA" Then $aComp[3] ='Pennsylvania'
If $aComp[3] = "RI" Then $aComp[3] ='Rhode Island'
If $aComp[3] = "SD" Then $aComp[3] ='South Dakota'
If $aComp[3] = "TN" Then $aComp[3] ='Tennessee'
If $aComp[3] = "TX" Then $aComp[3] ='Texas'
If $aComp[3] = "UT" Then $aComp[3] ='Utah'
If $aComp[3] = "VA" Then $aComp[3] ='Virginia'
If $aComp[3] = "WA" Then $aComp[3] ='Washington'
If $aComp[3] = "WV" Then $aComp[3] ='West Virginia'
If $aComp[3] = "WI" Then $aComp[3] ='Wisconsin'

WinActivate("PayPal")
Sleep(1000)
 Send($aComp[0] & "{tab}" & $aComp[1] & "{tab 2}" & $aComp[2] & "{tab}" & $aComp[3] & "{tab}" & $aComp[4] )

 

Share this post


Link to post
Share on other sites
On 12/28/2020 at 11:36 AM, Nine said:

Here a first draft.  If you find new format of address, include them in the array, we will see how we can solve it.

#include <Constants.au3>
#include <Array.au3>

Local $aAddr = [ _
  "Frank Conte 2133 Elm St. Gainesville FL, 45679.", _
  "Frank F. Conte" & @CRLF & "123 First Rd." & @CRLF & "New York NY, 12345." ]

Local $aComp

For $sAddr in $aAddr
  $aComp = StringRegExp($sAddr, "(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)", 1)
  _ArrayDisplay($aComp)
Next

 

@Nine

 

So far, I've found two variations that break the regex:

1. If the State is in small letters (eg fl instead of FL)

2. If there is a comma after the City (eg Orlando, FL)

Thanks...

 

Share this post


Link to post
Share on other sites
Posted (edited)

1. From everything I can see, it looks like the RegEx isn't dependent on capital letters. Using the global flag (?i) makes RegEx not be case-sensitive. You can add this to the (?s) flag at the beginning like (?si). Alternately, capture lowercase letters as well as uppercase -- from [A-Z] to [a-zA-Z]

2. You mean sometimes there isn't a comma? You can make something in RegEx optional by using a question mark.

3. Do you ever have zip code extensions? (a 4 digit code after the zip code) You won't capture them currently.

1:
    (?si)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)
    Or...
    (?s)([^\d]+)([^.]+\.)\h*(.*?)([a-zA-Z]{2}),\h*(\d+)
2:
    (?si)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),?\h*(\d+)
3:
    (?si)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),?\h*(\d+(?:-\d+)?)
Edited by seadoggie01
Zip... code :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
Share on other sites

Thank you so much @seadoggie01 !

The two issues are now corrected. Hopefully there won't be others.

I wish my brain was wired like yours to fully comprehend this incredibly helpful regex tool.

Share this post


Link to post
Share on other sites
20 minutes ago, fmendi said:

I wish my brain was wired like yours

No, trust me, you don't :D

20 minutes ago, fmendi said:

incredibly helpful regex tool

I think I learned just about everything I know from RegEx101.com. It's also amazingly helpful to test RegEx instead of trying it in a script repeatedly.


All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
Share on other sites
Posted (edited)

@fmendi
If you want to "split" the pattern to understand what each piace of it means, then you can paste the pattern here and read the description of the various pieces in the top-right side of the window :)

EDIT: Nice one @seadoggie01! :D

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

RegEx101.com is a great resource.! Thank you both for the suggestion. I have been trying different test strings to figure out how to make

StringRegExp($sAddr, "(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)", 1)

work without a period at the end of the street address (123 Elm St.), but my brain started hurting.

I took out the  \.  from the second capturing group   ([^.]+\.)  and it sort of worked, but the  period now appears in the third capturing group before the city  ie.

.  New York.

I would like for the regex to work both with and without a period at the end of the street address.

Sorry for continuing to ask for help, but know it is deeply appreciated.

Share this post


Link to post
Share on other sites
18 minutes ago, FrancescoDiMuro said:

@fmendi
Could you please post a bunch of test strings and the expected results? :)

Sure, Thanks...

1. John Ham 123 elm st. New York NY, 12323   -expected --->  1. John Ham  2. 123 elm st.   3. New York  4. NY  5. 12323  --->  Works

2. John Ham 123 elm st New York NY, 12323    -expected  --->  1. John Ham  2. 123 elm st  3. New York  4. NY  5. 12323   --->  Does not work because of the missing period (.)  after 123 elm st

 Eliminating \. from regex

3. John Ham 123 elm st. New York NY, 12323    -results in --->  1. John Ham  2. 123 elm st  3. .  New York  4. NY  5. 12323   ---> 

Share this post


Link to post
Share on other sites

Unless there is always a ending street name acronym (st - av - rd - blvd - ...), I am afraid it would be impossible to extract correctly all the times.  How about apartment numbers ?  And PO box ? 

 

 

Share this post


Link to post
Share on other sites
33 minutes ago, Nine said:

Unless there is always a ending street name acronym (st - av - rd - blvd - ...), I am afraid it would be impossible to extract correctly all the times.  How about apartment numbers ?  And PO box ? 

That why I use https://github.com/datamade/usaddress to parse addresses. I have a Ubuntu VM that takes the request and returns the parsed data.

Share this post


Link to post
Share on other sites

I understand that there are limitless variations that cannot be covered. 

In this particular situation, I am going to have to manipulate the address by adding a period after the street address, if it does not already exist,  before putting it through regex.

Edited by fmendi

Share this post


Link to post
Share on other sites

That seems to work fine if you correctly list all acronyms :

#include <Constants.au3>
#include <Array.au3>

Local $aAddr = [ _
  "Frank Conte 2133 Elm St. Gainesville, FL, 45679.", _
  "Frank F. Conte 123 First Rd. New York NY, 12345.", _
  "Frank Conte 2133 Elm blvd Gainesville fl, 45679.", _
  "Frank Conte 2133 Elm av Gaines Town, FL, 45679"]

Local $aComp
For $sAddr in $aAddr
  $aComp = StringRegExp($sAddr, "(?si)([^\d]+)(.*(?:st|av|blvd|rd))\.?\h*(.*?),?\h*([A-Z]{2}),\h*(\d+)", 1)
  _ArrayDisplay($aComp)
Next

 

Share this post


Link to post
Share on other sites

It's slightly more complicated, but the other thing you can try is to build your RegEx from a config file. Then, any time you come across an address (that doesn't work), you could have your program:

  1. Ask if there is a new acronym
  2. Add it the new acronym to the config then rebuild and retry the RegEx
  3. (Optionally) Save the address to review (and/or manually enter) later
Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...