I don’t mind posting the code, but it’s kinda big–375 lines. The guidelines don’t seem to limit the size of posted code, so here goes:
(* This script uploads regatta schedules, results, and trophy-point totals
to the Austin Rowing Club's Live Results website. Its
four handlers are called by FileMaker running RegattaBase.
Each of the three upload handlers reads a text file written by RegattaBase, adds html
code before and after the file's contents to make a valid html page, and sends the
resulting file to the Live Results website.
The initialization handler customizes the html "before" code using arguments
supplied by RegattaBase. The last argument is the path of the folder to be used
for the files it reads and writes.
*)
property footer : "<div id=\"footer\"><a name=\"latestResults\"></a>
<div class=\"floatLeft\">
<p>Questions or comments about these pages? </p>
<div class=\"spamVaccineStyle\">
<p >Contact
<script type=\"text/javascript\" inserter=\"Spam Vaccine 1.3\">
<!--
spam_vaccine( new Array(\"\\h\\r\\i\\c\\h\\a\\r\\d\\s\", \"\", \"\\s\\w\\b\\e\\l\\l\", \"\", \"\\n\\e\\t\", \"\"), new Array(\"Ham Richards\"), \"spam_vaccine/\" ) ;
//-->
</script>
<noscript>
hrichards<img width=\"11\" height=\"12\" align=\"absmiddle\" border=\"0\" alt=\" -at- \" src=\"spam_vaccine/at_medium.gif\">swbell.net
</noscript></p>
</div>
</div>
<a title=\"Austin Rowing Club website\" href=\"http://www.austinrowing.org\" ><img src=\"ARClogo.gif\" alt=\"Austin Rowing Club logo\" name=\"ARClogo\" width=\"78\" height=\"69\" align=\"top\" class=\"smallARClogo\"></a>
</div> </div>
<script type=\"text/javascript\">
var MenuBar1 = new Spry.Widget.MenuBar(\"MenuBar1\", {imgDown:\"SpryAssets/SpryMenuBarDownHover.gif\", imgRight:\"SpryAssets/SpryMenuBarRightHover.gif\"});
</script>
</body>
</html>"
global preSchedule
property postSchedule : "</dl><p> </p></div>" & footer
global scheduleNote, resultsNote
global preResults
property postResults : "</div>" & footer
global prePoints1, prePoints2
property postPoints : "</table><p> </p></div>" & footer
global uploadFolderPath
property dragon : false
property hostname : "[url=ftp://ftp.austinrowing.org/austinrowing.org/liveresults]ftp.austinrowing.org/austinrowing.org/liveresults[/url]"
property username : "austinrc"
property pwd : "¢¢¢¢¢¢¢¢¢¢¢¢"
on makeHeader(title, regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation) ----------------------------------------
if regattaType = "head" then
return "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
<meta name=\"viewport\" content=\"width=device-width\">
<title>" & regattaName & ": " & title & "</title>
<style type=\"text/css\" media=\"screen\">
<!--
-->
</style>
<link href=\"site.css\" rel=\"stylesheet\" type=\"text/css\">
<script type=\"text/javascript\" src=\"spam_vaccine/spam_vaccine.js\" inserter=\"Spam Vaccine 1.3\"></script>
<script src=\"SpryAssets/SpryMenuBar.js\" type=\"text/javascript\"></script>
<link href=\"SpryAssets/SpryMenuBarHorizontal.css\" rel=\"stylesheet\" type=\"text/css\">
<link href=\"swmq.css\" rel=\"stylesheet\" type=\"text/css\">
</head>
<body bgcolor=\"#ffffff\">
<div class=\"container\">
<div id=\"header\">
<h1>" & regattaHTMLname & "</h1>
<h2>" & regattaLocation & "<br> " & regattaDates & "</h2>
<div id=\"linkBar\">
<ul id=\"MenuBar1\" class=\"MenuBarHorizontal\">
<li><a href=\"day1results.html\">Results</a></li>
<li><a href=\"day1schedule.html\">Schedule</a></li>
<li><a href=\"penaltyGuide.html\">Penalties</a></li>
</ul>
</div>
</div>
<div id=\"content\">"
else
return "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">
<meta name=\"viewport\" content=\"width=device-width\">
<title>" & regattaName & ": " & title & "</title>
<style type=\"text/css\" media=\"screen\">
<!--
-->
</style>
<link href=\"site.css\" rel=\"stylesheet\" type=\"text/css\">
<script type=\"text/javascript\" src=\"spam_vaccine/spam_vaccine.js\" inserter=\"Spam Vaccine 1.3\"></script>
<script src=\"SpryAssets/SpryMenuBar.js\" type=\"text/javascript\"></script>
<link href=\"swmq.css\" rel=\"stylesheet\" type=\"text/css\">
<link href=\"SpryAssets/SpryMenuBarHorizontal.css\" rel=\"stylesheet\" type=\"text/css\">
</head>
<body bgcolor=\"#ffffff\">
<div class=\"container\">
<div id=\"header\">
<h1>" & regattaHTMLname & "</h1>
<h2>" & regattaLocation & "<br>" & regattaDates & "</h2>
<p>sponsored by " & regattaSponsor & "</p>
<div id=\"linkBar\">
<ul id=\"MenuBar1\" class=\"MenuBarHorizontal\">
<li><a href=\"index.html\" title=\"Home page\">Home</a></li>
<li><a href=\"day12schedule.html\" title=\"note on schedules\" class=\"MenuBarItemSubmenu\">Schedule</a>
<ul>
<li><a href=\"day1schedule.html\" title=\"Saturday schedule\">Saturday </a></li>
<li><a href=\"day2schedule.html\" title=\"Sunday schedule\">Sunday</a></li>
</ul>
</li>
<li><a href=\"day12results.html\" title=\"note on Results\" class=\"MenuBarItemSubmenu\">Results</a>
<ul>
<li><a href=\"day1DBresults.html\" title=\"Dragon Boat results\">Dragon Boats</a></li>
<li><a href=\"day12results.html\" title=\"Rowing results\" class=\"MenuBarItemSubmenu\">Rowing</a>
<ul>
<li><a href=\"day1results.html\" title=\"Saturday rowing results\">Saturday</a></li>
<li><a href=\"day2results.html\" title=\"Sunday rowing results\">Sunday</a></li>
</ul>
</li>
</ul>
</li>
<li><a href=\"pointsNote.html\" title=\"note on Points\" class=\"MenuBarItemSubmenu\">Points</a>
<ul>
<li><a href=\"pointsJuniors.html\" title=\"Juniors points\">Juniors</a></li>
<li><a href=\"pointsMasters.html\" title=\"Masters points\">Masters</a></li>
<li><a href=\"pointsAll.html\" title=\"All points\">All</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id=\"content\">"
end if
end makeHeader -------------------------------------------------------------------------------------------------------------
on initialize(regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation, uFP) -------------------------------------------------------------------------------------
set preSchedule to makeHeader("Schedule", regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation)
set preResults to makeHeader("Results", regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation)
set prePoints1 to makeHeader("Points", regattaType, regattaName, regattaHTMLname, regattaDates, regattaSponsor, regattaLocation) & "<H2>Trophy Point standings for "
set prePoints2 to " events</H2>
<h4>Points are computed using the USRowing formula
<a title=\"USRowing Rules of Rowing\"
href=\"http://www.usrowing.org/Libraries/Referees/2013RORfinalweb.sflb.ashx\">
(USRowing 2013 Rules of Rowing, page 66)</a>.</h4>"
set uploadFolderPath to uFP
set initialized to true
end initialize --------------------------------------------------------------------------------------
on uploadDragonResults(dayNumber, doUpload, resultsNote)
set dragon to true
uploadResults(dayNumber, doUpload, resultsNote)
end uploadDragonResults ------------------------------------------------
on uploadResults(dayNumber, doUpload, resultsNote) -----------------------------------------------------------------------
local resultsTEXTpath, resultsTEXTfile, resultsHTMLpath, resultsHTMLfile, resultsFileName
if dragon then
set dbTag to "DB"
else
set dbTag to ""
end if
set resultsTEXTpath to (uploadFolderPath & dbTag & "results.tab") -- input file
set resultsFileName to "day" & dayNumber & dbTag & "results.html"
set resultsHTMLpath to (uploadFolderPath & resultsFileName) -- output file
try
set resultsTEXTfile to open for access file resultsTEXTpath
on error msg
display dialog "regattaUploads/uploadResults: " & msg buttons {"QUIT"} default button "QUIT"
close access file resultsTEXTpath
return
end try
try
set resultsHTMLfile to open for access file resultsHTMLpath with write permission
on error msg
display dialog "regattaUploads/uploadResults: " & msg buttons {"QUIT"} default button "QUIT"
close access file resultsHTMLpath
return
end try
set eof resultsHTMLfile to 0 -- erase it if it exists
-- build file results.html
write preResults to resultsHTMLfile as «class utf8»
if dragon then
write ("<H2>Dragon Boat Results as of " & timeNow() & "</H2>" & return & return) to resultsHTMLfile as «class utf8»
else
write ("<H2>Results as of " & timeNow() & "</H2>" & return ¬
& "<H2>" & resultsNote & "</H2>" & return & return ¬
& ¬
"<H2><a href=\"#latestResults\">Latest Results</a></H2>") to resultsHTMLfile as «class utf8»
end if
write (read resultsTEXTfile as «class utf8») to resultsHTMLfile as «class utf8»
write postResults to resultsHTMLfile as «class utf8»
close access resultsTEXTfile
close access resultsHTMLfile
-- upload results.html
set posixResultsPath to POSIX path of resultsHTMLpath
set ftpScript to ("curl -T " & quoted form of posixResultsPath & " ftp://" & username & ":" & pwd & "@" & hostname & "/" & resultsFileName)
if doUpload > 0 then do shell script ftpScript
set dragon to false
end uploadResults ------------------------------------------------------------------------------
on uploadPoints(tag, doUpload, pointsNote) -------------------------------------------------------------------------------
-- tag specifies whether point totals are for Junior events, Masters events, or all events.
-- Its value should be "Juniors", "Masters", or "All".
local rpPath, rpFile, rpLine, wpPath, wpFile, wpLine
set rpPath to uploadFolderPath & "rawPoints" & tag & ".tab"
set wpPath to uploadFolderPath & "weightedPoints" & tag & ".tab"
set pointsPath to uploadFolderPath & "points" & tag & ".html"
try
set rpFile to open for access file rpPath
on error msg
display dialog "regattaUploads/uploadPoints: " & msg buttons {"QUIT"} default button "QUIT"
close access file rpPath
return
end try
try
set wpFile to open for access file wpPath
on error msg
display dialog "regattaUploads/uploadPoints: " & msg buttons {"QUIT"} default button "QUIT"
close access file wpPath
return
end try
try
set pointsFile to open for access file pointsPath with write permission
on error msg
display dialog "regattaUploads/uploadPoints: " & msg buttons {"QUIT"} default button "QUIT"
close access file pointsPath
end try
set eof pointsFile to 0 -- erase if it exists
write -257 to pointsFile as small integer starting at 0 -- Unicode BOM
write prePoints1 to pointsFile as Unicode text
write tag to pointsFile as Unicode text
write prePoints2 to pointsFile as Unicode text
write ("<H3>" & timeNow() & "</H3>" & return & return & "<table width=\"80%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">" & return) to pointsFile as Unicode text
write "<tr><td align=\"center\"><b><font size=\"+1\">Total Points</font></b></td><td></td><td></td><td align=\"center\"><b><font size=\"+1\">Points per Entry</font></b></td></tr>" to pointsFile as Unicode text
set endFile to false
repeat until endFile
try
set rpLine to read rpFile before return
set wpLine to read wpFile before return
write rpLine to pointsFile as Unicode text
write wpLine to pointsFile as Unicode text
write return to pointsFile as Unicode text
on error
set endFile to true
close access rpFile
close access wpFile
end try
end repeat
write postPoints to pointsFile as Unicode text
close access pointsFile
-- upload Points.html
set posixPointsPath to POSIX path of pointsPath
set ftpScript to ("curl -T " & quoted form of posixPointsPath & " ftp://" & username & ":" & pwd & "@" & hostname & "/points" & tag & ".html")
if doUpload > 0 then do shell script ftpScript
end uploadPoints -----------------------------------------------------------------------------------------------------
on uploadSchedule(dayNumber, doUpload, scheduleNote) ------------------------------------------------------------------------------------
local scheduleTEXTpath, scheduleTEXTfile, scheduleHTMLpath, scheduleHTMLfile
set scheduleTEXTpath to (uploadFolderPath & "schedule.tab") -- input file
set scheduleHTMLpath to (uploadFolderPath & "day" & dayNumber & "schedule.html") -- output file
try
set scheduleTEXTfile to open for access file scheduleTEXTpath
on error msg
display dialog "regattaUploads/uploadSchedule: " & msg buttons {"QUIT"} default button "QUIT"
close access file scheduleTEXTpath
return
end try
try
set scheduleHTMLfile to open for access file scheduleHTMLpath with write permission
on error msg
display dialog "regattaUploads/uploadSchedule: " & msg buttons {"QUIT"} default button "QUIT"
close access file scheduleHTMLpath
return
end try
set eof scheduleHTMLfile to 0 -- erase file if it exists
-- build file schedule.html
write preSchedule to scheduleHTMLfile as «class utf8»
write ("<H2>Race Schedule as of " & timeNow() & "</H2>" & return ¬
& "<H2>" & scheduleNote & "</H2>" & return ¬
& "<H3>Numbers in parentheses are <i>handicaps</i>.</H3>" & "<H3>Letters (<I>A</I>, <i>B</I>, <I>C</I>,...) following team names are <i>seeds</i>.</H3><DL>") ¬
to scheduleHTMLfile as «class utf8»
write (read scheduleTEXTfile as «class utf8») to scheduleHTMLfile as «class utf8»
write postSchedule to scheduleHTMLfile as «class utf8»
close access scheduleTEXTfile
close access scheduleHTMLfile
-- upload schedule.html
set posixSchedulePath to POSIX path of scheduleHTMLpath
set ftpScript to ("curl -T " & quoted form of posixSchedulePath & " ftp://" & username & ":" & pwd & "@" & hostname & "/day" & dayNumber & "schedule.html")
if doUpload > 0 then do shell script ftpScript
return ftpScript
end uploadSchedule ----------------------------------------------------------------------------------
on timeNow() --------------------------------------------------------------------------------------
-- create time and day string, omitting seconds
set t to time string of (current date)
set n to length of t
return (((characters 1 thru (n - 6) of t) & (characters (n - 2) thru n of t)) as text) & " " & date string of (current date)
end timeNow --------------------------------------------------------------------------------------
When compiled in AppleScript Editor it falls flat. Compiled in Script Debugger it works perfectly.
Comments welcome,
–Ham