I moderate a fairly active forum and any little bit of help I can get the better. Recently our developers added the vaispy mod to the forums. This allows for a real time feed of what is happening. I decided to try and write a script that scanned the ispy XML for specific NO NOs on these forums. It works pretty good, though I’m sure there are some issues with my script. However, when my script gets to the point where it needs to check if the flagged XML even has been flagged previously it tends to ignore my pid.txt file and re-open the link in Firefox.
Sample Site with vaispy: http://forums.finalgear.com/vaispy.php
Sample XML with vaispy: http://forums.finalgear.com/vaispy.php?do=xml
Sample naughty.txt
Sample pid.txt
How the script works (Should)
Loads Flags “naughtywords” to a list
Activates Safari
Loads vaispy XML
Gathers source
Parses the source into a list using the tag in the XML
Loops through each item in the list and extracts whether it is a new thread or new post
If it is a new thread it then extracts the title
if it is a new post it extracts the preview
The script then scans the extracted Title -or- Preview against a the naughty words list using offset of
If scan is positive it grabes the postid from the event list
The postID is compared against a txt file of previously flagged postids
If it is there it should ignore the flag and continue on to the next event
If it is NOT there it should add the postid to the pid.txt assemble a URL and open that URL in firefox
What happens
When the script reaches the part where it needs to compare the postid against the pid.txt sometimes it will ignore the test if found = 0 then and then open the URL EVEN if found ≠0
EG the postid is already in the pid.txt but the script still opens it in Firefox.
set region to "na"
set XMLURL to "http://" & region & ".<REMOVED>.com/board/vaispy-secret.php?do=xml"
-- Load flags
set naughtylist to {}
set Shows to paragraphs of (read POSIX file "/Users/aaon/Desktop/naughty.txt")
repeat with nextLine in Shows
if length of nextLine is greater than 0 then
copy nextLine to the end of naughtylist
end if
end repeat
-- Load Safari
tell application "Safari"
-- open safari and prepare to load XML
activate
make new document at end of documents
set URL of document 1 to ""
my waitforload()
repeat
-- Load XML
set URL of tab 1 of front window to XMLURL
delay 10
-- Get page source
set currentTab to current tab of front window
set currentSource to currentTab's source
-- Load source into array
set event_array to {}
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "</event>"
set event_array to text items of currentSource
-- Loop through array
repeat with myevent in event_array
try
-- Check if end of array
set event_test to offset of "</events>" in myevent
if event_test = 0 then
-- Check alert type
set alerttype to my gbt(myevent, "<what>", "</what>")
-- Alert is New Thread
if alerttype = "New Thread" then
set scan to my gbt(myevent, "<title>", "</title>")
-- Alert is New Post
else
set scan to my gbt(myevent, "<preview>", "</preview>")
end if
-- Compare scan to Flagslist
repeat with naughtyword in naughtylist
-- Check for Flags
set test to offset of naughtyword in scan
-- Test fails
if test ≠0 then
-- Get postID
set postid to my gbt(myevent, "<postid>", "</postid>")
-- Load postid list for comparison
set pid to {}
set Shows to paragraphs of (read POSIX file "/Users/aaon/Desktop/pid.txt")
repeat with nextLine in Shows
if length of nextLine is greater than 0 then
copy nextLine to the end of pid
end if
end repeat
delay 1
-- Compare postid to postid list
set found to 0
repeat with s_pid in pid
--display dialog "Post ID:" & postid & " Scan Post ID:" & s_pid
delay 0.25
if s_pid = postid then
set found to 1
else
set found to 0
end if
end repeat
-- If postID not found
if found = 0 then
-- Asemble URL
set FFURL to "http://" & region & ".<REMOVED>.com/board/showthread.php?p=" & postid & "&highlight=" & naughtyword
-- Log postID. Open link
do shell script "echo " & quoted form of postid & ">> ~/Desktop/pid.txt"
delay 1
do shell script "open -a Firefox " & quoted form of FFURL
end if
end if
end repeat
end if
on error
delay 10
set URL of tab 1 of front window to XMLURL
delay 10
end try
end repeat
delay 10
end repeat
end tell
on gbt(myText, fd, sd)
try
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to fd
set a to text item 2 of myText
set AppleScript's text item delimiters to sd
set b to text item 1 of a
return b
on error
tell application "Safari"
delay 10
set URL of tab 1 of front window to XMLURL
end tell
end try
end gbt
on waitforload()
--check if page has loaded
set loadflag to 0
repeat until loadflag is 1
delay 0.5
tell application "Safari"
set test_html to source of document 1
end tell
try
set zarg to text ((count of characters in test_html) - 10) thru (count of characters in test_html) of test_html
if "</html>" is in text ((count of characters in test_html) - 10) thru (count of characters in test_html) of test_html then
set loadflag to 1
end if
end try
end repeat
end waitforload