Description
SCRIPT NO LONGER WORKS!
Twitter changed their API a while back, which means that this script no longer works. I am leaving it up as a reference example of working with XML and, perhaps, I'll revise this to use the new API in the future. If you have a lot of followers on Twitter, it can be a pain to figure out if someone is following you. This is a fun, simple script that demonstrates how to use the Twitter API to find out quickly! Change the property at the top of the script to your account name (or any working Twitter account) and run the script. You'll get a dialog box that let's you type in a user name to check. Once entered, the script checks to see if the account name you typed in is following you. After you enter your account name, be sure to save this script as an app for even easier use. Have fun!The Code
(*
http://veritrope.com
TWITTER FOLLOWER CHECK
Version 1.0
April 13, 2011
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/code/twitter-follower-check
*)
(*
======================================
// USER SWITCHES
======================================
*)
-- CHANGE THIS VALUE TO THE ACCOUNT NAME
-- YOU WANT TO CHECK THE FOLLOWERS OF...
property username : "ACCOUNT"
(*
======================================
// OTHER PROPERTIES
======================================
*)
property theLists : {}
property theScreenname : ""
(*
======================================
// MAIN PROGRAM
======================================
*)
--ICON PATH
set p to (path to "csrv")'s POSIX path & "CoreTypes.bundle"
--SCREENNAME
set theScreenname to text returned of (display dialog "Enter The Screen Name To Check" default answer theScreenname with title ¬
"Twitter Follower?" with icon (path to resource "GroupIcon.icns" in bundle p))
--GET TWITTER LISTS
set getLists to "http://api.twitter.com/1/friendships/exists.xml?user_a=" & theScreenname & "&user_b=" & username
set rawLists to do shell script "curl -siL " & (quoted form of getLists)
set the_code to items 10 thru 12 of rawLists as string
--ON ERROR
if the_code is greater than 400 then
set startOffset to (offset of "<error>" in rawLists)
set endOffset to (offset of "</error>" in rawLists)
set the_Error to (characters (startOffset + 7) thru (endOffset - 1) of rawLists) as string
--set the_error to
(display dialog "Error:
" & the_Error with title ¬
"Twitter Follower?" with icon (path to resource "GroupIcon.icns" in bundle p))
else
--STRIP HEADER
set oldDelim to AppleScript's text item delimiters
set newDelim to return & return
set AppleScript's text item delimiters to newDelim
set theLists to second text item of rawLists
set AppleScript's text item delimiters to oldDelim
--PARSE XML INTO ANSWER
set removeOpen to my replaceString(theLists, "<friends>", "")
set the_answer to my replaceString(removeOpen, "</friends>", "")
--CONSTRUCT DIALOG BOX
if the_answer is "false" then
set is_Not to "NOT "
else
set is_Not to ""
end if
set final_answer to theScreenname & " is " & is_Not & "following you."
display dialog final_answer with title ¬
"Twitter Follower?" with icon (path to resource "GroupIcon.icns" in bundle p)
end if
(*
======================================
// SUBROUTINES
======================================
*)
--REPLACE
on replaceString(theString, theOriginalString, theNewString)
set theNum to 0
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theOriginalString}
set theStringParts to text items of theString
if (count of theStringParts) is greater than 1 then
set theString to text item 1 of theStringParts as string
repeat with eachPart in items 2 thru -1 of theStringParts
set theString to theString & theNewString & eachPart as string
set theNum to theNum + 1
end repeat
end if
set AppleScript's text item delimiters to od
return theString
end replaceString
http://veritrope.com
TWITTER FOLLOWER CHECK
Version 1.0
April 13, 2011
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/code/twitter-follower-check
*)
(*
======================================
// USER SWITCHES
======================================
*)
-- CHANGE THIS VALUE TO THE ACCOUNT NAME
-- YOU WANT TO CHECK THE FOLLOWERS OF...
property username : "ACCOUNT"
(*
======================================
// OTHER PROPERTIES
======================================
*)
property theLists : {}
property theScreenname : ""
(*
======================================
// MAIN PROGRAM
======================================
*)
--ICON PATH
set p to (path to "csrv")'s POSIX path & "CoreTypes.bundle"
--SCREENNAME
set theScreenname to text returned of (display dialog "Enter The Screen Name To Check" default answer theScreenname with title ¬
"Twitter Follower?" with icon (path to resource "GroupIcon.icns" in bundle p))
--GET TWITTER LISTS
set getLists to "http://api.twitter.com/1/friendships/exists.xml?user_a=" & theScreenname & "&user_b=" & username
set rawLists to do shell script "curl -siL " & (quoted form of getLists)
set the_code to items 10 thru 12 of rawLists as string
--ON ERROR
if the_code is greater than 400 then
set startOffset to (offset of "<error>" in rawLists)
set endOffset to (offset of "</error>" in rawLists)
set the_Error to (characters (startOffset + 7) thru (endOffset - 1) of rawLists) as string
--set the_error to
(display dialog "Error:
" & the_Error with title ¬
"Twitter Follower?" with icon (path to resource "GroupIcon.icns" in bundle p))
else
--STRIP HEADER
set oldDelim to AppleScript's text item delimiters
set newDelim to return & return
set AppleScript's text item delimiters to newDelim
set theLists to second text item of rawLists
set AppleScript's text item delimiters to oldDelim
--PARSE XML INTO ANSWER
set removeOpen to my replaceString(theLists, "<friends>", "")
set the_answer to my replaceString(removeOpen, "</friends>", "")
--CONSTRUCT DIALOG BOX
if the_answer is "false" then
set is_Not to "NOT "
else
set is_Not to ""
end if
set final_answer to theScreenname & " is " & is_Not & "following you."
display dialog final_answer with title ¬
"Twitter Follower?" with icon (path to resource "GroupIcon.icns" in bundle p)
end if
(*
======================================
// SUBROUTINES
======================================
*)
--REPLACE
on replaceString(theString, theOriginalString, theNewString)
set theNum to 0
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theOriginalString}
set theStringParts to text items of theString
if (count of theStringParts) is greater than 1 then
set theString to text item 1 of theStringParts as string
repeat with eachPart in items 2 thru -1 of theStringParts
set theString to theString & theNewString & eachPart as string
set theNum to theNum + 1
end repeat
end if
set AppleScript's text item delimiters to od
return theString
end replaceString