Everything seems to work except one thing: the price retrieved from the page is in a special format, for example 5880 is written as 5 880. So I can’t compare it with the trigger price. is there any space strip function in AppleScript (you know, if I use the function on the downloaded price it will get rid of the spaces in the number,
5 880 gets in, and 5880 goes out)? I hope it is clear, what I want to tell. And here is the code:
property theStock : “”
property theTriggerPrice : “1000”
property veszElad : “”
property sourceURL : “http://www.bet.hu/onlinesz/10000122.html?uio=”
property symbola : “>”
property symbolb : “”
property delimiter1 : {“"right" nowrap>”}
property delimiter2 : {“”}
property mailAddress1 : “sms@messaging.clickatell.com”
property mailAddress2 : “sardaukar@vipmail.hu”
property mailAddress3 : “infrared@freemail.hu”
property theAcc : “” – accTelszam
display dialog “Melyik részvény árfolyamát figyeljem?” default answer “FOTEX”
set theStock to text returned of the result
display dialog “Milyen árfolyamnál küldjek figyelmeztetést?” default answer “1000”
set theTriggerPrice to text returned of the result
display dialog “Eladásra vagy vételre játszik?” buttons {“Eladásra”, “Vételre”} default button 2
set veszElad to button returned of the result
display dialog “Irja be a telefonszámát, amire az értesÃtôt küldöm:” default answer “36”
set theAcc to text returned of the result
on idle
set thePrice to getPrice(theStock, sourceURL)
display dialog ({"A ", theStock, " reszveny aktualis arfolyama : " & thePrice} as string) buttons {“OK”} default button “OK”
if veszElad is “Vételre” then
if theTriggerPrice ≥ thePrice then – here is the problem, the term will be always true
– sendMail(theAcc)
display dialog theTriggerPrice & thePrice & veszElad
end if
else
if theTriggerPrice ≤ thePrice then – here is also problem, here will be the term always false
– sendMail(theAcc)
display dialog theTriggerPrice & thePrice & veszElad
end if
end if
return 60
end idle
on getPrice(theShare, theURL)
set sourceCode to (do shell script “curl " & theURL) as string
set AppleScript’s text item delimiters to {symbola & theShare & symbolb}
set tmpSource to (text item 2 of sourceCode) as string
set AppleScript’s text item delimiters to {delimiter1}
set tmpSource to (text item 2 of tmpSource) as string
set AppleScript’s text item delimiters to {delimiter2}
set tmpValue to (text item 1 of tmpSource) as string
set AppleScript’s text item delimiters to {”"}
return tmpValue
end getPrice
on sendMail(accTelszam)
tell application “Mail”
set newMessage to (make new outgoing message with properties ¬
{subject:“Reszveny arfolyam”, content:“api_id:584171
user:AFagens
password:warning522
from:Arfolyam Figyelo
to:” & accTelszam & "
text: A(z) " & theStock & " részvény árfolyama elérte a " & theTriggerPrice & " értéket"})
tell newMessage
– set visible to true
set sender to “Arfolyam Figyelo Mobile@t-online.hu”
make new to recipient at end of to recipients with properties {name:“sms@messaging.clickatell.com”, address:mailAddress2}
send newMessage
end tell
end tell
end sendMail
The other parts work well (or at least I think so), but if you have any comment, please tell me (but please, be quick, the deadline is near!).