AppleScript C Perl Shell Xcode Other

Withdraw funds from PayPal automatically

Post Reply
coding / applescript     Views: 2504Prev .. Next
Withdraw funds from PayPal automaticallyPosted: Thursday, June 17, 2010 [18:17:42] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
PayPal offers funds daily "auto sweep" but what if you want to keep a portion of funds in your PayPal account and/or want only withdraw a preset amount?
You may also need to withdraw pre-set amounts to multiple accounts, say kids college account, your saving account and checking account.
PayPal offers nothing to withdraw automatically to multiple Bank Accounts.

Here is what we use on daily basis to withdraw money from our PayPal account to multiple Bank accounts.
AppleScript runs automatically after midnight each day. It verifies PayPal balance and if it is below threshold - nothing withdrawn.
View Codetell application "System Events"
if not (exists process "Safari") then
set wCounter to 0
else
set wCounter to 1
end if
end tell

-- now we kill Safari processes (close the program) as PayPal sometimes
-- acting-up if too many Safari windows opened
if wCounter > 0 then
quit application "Safari"
delay 3
-- get all running processes
set isOn to do shell script "ps axww"
delay 1
if isOn contains "Safari" then
-- find Safari PID
set safari_pid to do shell script "perl -e '$d = `ps ax | grep Safari`;$d =~ s#(\\d+)( )(.*?)(Applications/Safari)(.*?)(\\n|\\r)##;$d=$1;print $d;'"
-- and kill it
do shell script "kill -9 " & safari_pid
end if
end if

delay 1
-- now start new Safari copy
tell application "Safari" to activate
delay 3
-- make sure is active in Safari preferenses
tell application "System Events"
tell application process "Safari"
keystroke "," using {command down}
delay 2
get value of static text 1 of window 1
copy the result as string to varWindowName
click button "Security" of tool bar 1 of window varWindowName
delay 2
get value of checkbox "Enable Java" of group 1 of group 1 of window "Security"
copy the result as number to varResult
if varResult = 0 then
click checkbox "Enable Java" of group 1 of group 1 of window "Security"
end if
get value of checkbox "Enable " of group 1 of group 1 of window "Security"
copy the result as number to varOption
if varOption = 0 then
click checkbox "Enable " of group 1 of group 1 of window "Security"
end if
delay 2
click button 1 of window "Security"
end tell
end tell

delay 2
tell application "Safari"
make new document
delay 2
-- go to PayPal site
set URL of document 1 to "https://www.paypal.com/us/"
set myURL to URL of document 1
delay 10
set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 30
set my_delay to 1
-- wait for page to load
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "Untitled" then
delay my_delay
else
set web_page_is_loaded to true
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat
delay 1
do "document.getElementById('login_email').focus()" in document 1
end tell
delay 2
tell application "System Events"
tell process "Safari"
delay 2
-- this is your PayPal login email address
keystroke "your_login_email_address"
delay 2
keystroke tab
delay 1
-- this is your PayPal Account Password
keystroke "paypal_password"
delay 2
keystroke return
delay 2
end tell
end tell

-- now make sure the page is loaded again
tell application "Safari"
delay 10
set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 30
set my_delay to 1
set mid_delay to 0
repeat until web_page_is_loaded is true
if name of window 1 contains "Credit Card Processing" or name of window 1 contains "Logging" then
delay my_delay
else
if mid_delay > 0 then
set web_page_is_loaded to true
else
set mid_delay to 1
delay 4
end if
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat
end tell
delay 2

set html_list to ""

tell application "System Events"
tell process "Safari"
-- Esc key to make sure Safari standing still and not loading anything
key code 53
delay 3
keystroke return
delay 2
keystroke "a" using {command down}
delay 2
keystroke "c" using {command down}
delay 2
-- get the page content
set html_list to (the clipboard) as text
end tell
end tell
-- now get the PayPal account balance
-- Perl script determines if you have enough funds for withdrawal
-- it prints "good" if your pre-set minimum amoount is available
set Amount to do shell script ("echo " & quoted form of html_list & " | perl /paypal.balance.cgi")
set html_list to ""
set linkName to ""

if Amount contains "good" then -- IF AMOUNT MORE THAN A PRESET

tell application "Safari"

set LinkPresent to ""
set AllLinks to ""
set TransMatched to ""
set exitNmbr to 5
set LinkPresent to (do "document.links.length" in document 1)
set LinkPresent to LinkPresent - 1
set Split to ""
-- now get the "Withdrawal" link on PayPal page and focus on it
repeat with n from 0 to LinkPresent
set linkURL to (do "document.links[" & n & "].href" in document 1)
set linkName to (do "document.links[" & n & "].text" in document 1)
if linkName contains "Withdraw" then
do "document.links[" & n & "].focus();" in document 1
delay 1
set LinkPresent to n
exit repeat
end if -- TRANSFER TO BANK ACCOUNT LINK END
end repeat
delay 1
end tell -- end Safari tell
delay 5

-- endLoop is the number of Bank Accounts linked to your PayPal Account you could
-- withdraw funds to
-- if you have one Bank Account linked - change endLoop to "1"
-- if you have multiple accounts linked and want transfer to the first account on the list
-- in select field endLoop 1 is sufficient
-- if account is down the list and not the first one - you'd need to change endLoop to that
-- number on the list and skip all accounts above and add a procedure for that in a loop below
-- here our program withdraws 5 to each bank account

set endLoop to 3
repeat with k from 1 to endLoop
tell application "Safari"
set AllLinks to AllLinks + 1

-- REPEAT FOR ALL ACCOUNTS

tell application "System Events"
tell application process "Safari"
-- open "Withdraw" page in a new window so we do not have to go back and forth
keystroke return using {command down} -- open new window
delay 3
end tell
end tell
-- Wait till page is loaded

set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 20
set my_delay to 2
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "My Account" or name of window 1 contains "https" then
delay my_delay
else
if name of window 1 contains "Withdraw Funds" then
set web_page_is_loaded to true
end if
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat -- END REPEAT LOADING PAGE

set LinksAll to ""
set LinksAll to (do "document.links.length" in document 1)
set LinksAll to LinksAll - 1
set Split to ""
set lnkNam to ""
-- get link "Transfer funds to your bank" - focus on it and click it
repeat with g from 0 to LinksAll
set lnkURL to (do "document.links[" & g & "].href" in document 1)
set lnkNam to (do "document.links[" & g & "].text" in document 1)
if lnkNam contains "funds to your bank" then
set LinksAll to g
do "document.links[" & g & "].focus();" in document 1
delay 1
set LinkPresentZ to 1
if LinkPresentZ > 0 then
exit repeat
end if
exit repeat
end if -- WITHDRAW FUNDS LINK END
end repeat
set LinkPresentZ to ""
delay 2
tell application "System Events"
tell application process "Safari"
keystroke return
delay 1
end tell
end tell
delay 12

set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 20
set my_delay to 2
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "My Account" or name of window 1 contains "https" then
delay my_delay
else
if name of window 1 contains "Withdraw Funds by Electronic" then
set web_page_is_loaded to true
end if
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat -- END REPEAT LOADING PAGE
-- now enter amount to withdraw by getting the form field "amount" and focusing on it

do "document.getElementById('amount').focus()" in document 1
tell application "System Events"
tell application process "Safari"
keystroke "5" -- amount to withdraw
delay 2
-- now if this is the second and more linked account down the list - select it
if k > 1 then
keystroke tab
delay 2
key code 125 -- arrow down key
delay 1
key code 125 -- arrow down key
delay 1
if k > 2 then
key code 125 -- arrow down key
delay 1
end if
end if
keystroke return
end tell
end tell
delay 8

set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 20
set my_delay to 2
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "My Account" or name of window 1 contains "https" then
delay my_delay
else
if name of window 1 contains "Withdraw Funds by Electronic" then
set web_page_is_loaded to true
end if
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat -- END REPEAT LOADING PAGE
delay 3
do "document.getElementById('amount').focus()" in document 1
delay 2
tell application "System Events"
tell application process "Safari"
keystroke return
end tell
end tell
delay 15

set LinksAllr to ""
set LinksAllr to (do "document.links.length" in document 1)
set LinksAllr to LinksAllr - 1
set Split to ""
set lkNam to ""
repeat with g from 0 to LinksAllr
set lkURL to (do "document.links[" & g & "].href" in document 1)
set lkNam to (do "document.links[" & g & "].text" in document 1)
if lkNam contains "Learn More" then
set LinksAllr to g
do "document.links[" & g & "].focus();" in document 1
delay 1
set LinkPresentZ to 1
if LinkPresentZ > 0 then
exit repeat
end if
exit repeat
end if -- WITHDRAW FUNDS LINK END
end repeat
set LinkPresentZ to ""

tell application "System Events"
tell application process "Safari"
keystroke tab
delay 2
keystroke return
delay 17
keystroke "w" using {command down}
delay 2
end tell
end tell

-- this is optional report writing - comment it out if you don't need it
if k is endLoop then
-- report completed all accounts, just write an empty file for other programs to see
-- in case you're running a daemon - this file could be used to verify result
do shell script "echo " & quoted form of k & " > /ddoneWithdraw.txt"
end if
-- END REPEAT FOR ALL ACCOUNTS
end tell -- open Safari end
end repeat
delay 1

end if -- END IF AMOUNT MORE THAN PRE-SET

-- now close the Safari window or use "q" instead of "w" to quit Safari
delay 3
tell application "System Events"
tell process "Safari"
keystroke "w" using {command down}
end tell
end tell


and this is paypal.balance.cgi Perl script that actually checks PayPal Balance

View Code#!/usr/bin/perl
unless($ENV{'SECURITYSESSIONID'}) {
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local:/usr/local/bin';
}
$vr = ;
$vr =~ s#\$\d{1,6}\.\d{2}#$&#;$amount = $&;
if($amount =~ m/\./) {($amount,$sh) = split(/\./,$amount);}
$amount =~ s/\D//g;$treshold=49; ## minimum amount on your PayPal account to initiate withdrawal
if($amount > $treshold) {
print "good";
}
else {print "Amount: $amount\n";$sendmail = '/usr/sbin/sendmail -t -oi';
# this is optional email sent if no withdrawal was made Today - uncomment exit(0); below if you
# do not want email to be sent
# please note escaped \@ signs - make sure they're escaped if written like that
# exit(0);
open(MAIL,"|$sendmail");
print MAIL <<EOM;
From: your_mac\@mac.email.com
To: your_email\@address.com
Subject: Kids deposit NOT made

Kids deposit NOT made Today as Deposit on PayPal is: \$$amount
Treshold is: \$$treshold (when system sends a deposit)
EOM
close(MAIL);
} ## END AMOUNT IS LESS THAN

It works with present PayPal site. Please remember, if PayPal changes the structure of their site - this program may (or may not) stop working.There's no place like ~
coding / applescriptPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group