This script lets you vote and keep tabs on the action! (what do you mean you’ve never heard of GameFaqs and their yearly battle to the death of video game characters old and new?) Anyways, this script extracts the poll from the page, lets you vote and submit an html form with curl (-d name=val) and presents the results… as long as the poll only has two options display dialog works well. Mostly though this demonstrates curl’s -d… and let’s you cheer on your contender! Go Crono!!
OS version: OS X
property lastChecked : missing value
todaysPoll()
on todaysPoll()
set pollId to do shell script (pollHTML() & getPollNumber())
set today to day of (current date)
if (today is not equal to lastChecked) then
set contenders to words of (do shell script (pollHTML() & getContenders()))
set rocky to button returned of (display dialog "Who's it gonna be?" buttons (contenders & "View Results"))
if rocky is "View Results" then
set results to words of (do shell script (viewResults(pollId) & parseResults()))
else
if rocky is the first item of contenders then
set contenderId to 1
else
set contenderId to 2
end if
log contenderId
set results to words of (do shell script (viewResults(pollId) & parseResults()))
end if
else
set results to words of (do shell script (viewResults(pollId) & parseResults()))
end if
set results to stitchResults(results)
display dialog results
end todaysPoll
on pollHTML()
"curl 'http://gamefaqs.com/index.html' | grep -A5 \"/poll/index.html\".*Character "
end pollHTML
on getContenders()
"| sed -ne 's/<input.*>\\(.*\\)<br>/\\1/p'"
end getContenders
on getPollNumber()
"| sed -ne 's/.*\\/poll\\/index.html.poll.\\(....\\).*/\\1/p'"
end getPollNumber
on postForm(choice, pollId)
"curl -d opt=" & choice & " -d poll=" & pollId & " [url=http://gamefaqs.com/poll/index.html]http://gamefaqs.com/poll/index.html"[/url]
end postForm
on viewResults(pollId)
"curl [url=http://gamefaqs.com/poll/index.html?poll=]http://gamefaqs.com/poll/index.html?poll="[/url] & pollId
end viewResults
on parseResults()
"| grep 'TOTAL.VOTES' | perl -pe 's/<.*?>/ /g'"
end parseResults
on stitchResults(results)
results's item 1 & " " & results's item 2 & "% " & results's item 3 & ¬
"
" & results's item 4 & " " & results's item 5 & "% " & result's item 6 & ¬
"
" & results's item 7 & " " & results's item 8 & ": " & results's item 9
end stitchResults