addfile ./Makefile hunk ./Makefile 1 +#OCDIR = $(shell ocamlc -where) +#OFLAGS = -I $(OCDIR)/dsf -g -verbose + +afn: afn.hs + ghc --make -O2 -W afn.hs -o afn + +#afn: afn.ml +# ocamlc $(OFLAGS) str.cma unix.cma dsf.cma time.ml cgi.ml afn.ml -o $@ +# cp afn /usr/lib/cgi-bin/afn + +mytop: Makefile + ocamlmktop $(OFLAGS) str.cma unix.cma dsf.cma time.ml cgi.ml -o mytop + +#clean: +# rm -f afn *.cm[oaix] *.cmxa addfile ./afn.hs hunk ./afn.hs 1 +#!/usr/bin/env runghc + +-- This is a CGI script that allows you to link directly to records in the +-- familysearch.org Ancestral File using the AFN number. + +import System.Unix.Process +import Data.ByteString.Lazy.Char8 (empty, unpack) +import Data.List (isPrefixOf, tails, find, lookup) +import Data.Maybe (fromJust) +import Network.CGI +import Network.CGI.Protocol (cgiInputs, inputValue) +import Network.CGI.Monad (cgiGet) + +main = runCGI afn + +afn :: CGIT IO CGIResult +afn = + do alist <- (cgiGet cgiInputs) + let file = inputValue (fromJust (lookup "file_number" alist)) + (out, _err, _code) <- liftIO $ lazyCommand ("curl -s 'http://www.familysearch.org/Eng/Search/customsearchresults.asp?date_range_index=0&type=0&LDS=0&event_index=0&date_range=0&file_number=" ++ unpack file ++ "&standardize=N&submit=Search&clear=Clear'") empty >>= return . collectOutputUnpacked + let uri = maybe Nothing (Just . takeWhile (/= '"')) (find (isPrefixOf "af/individual_record.asp?recid=") (tails out)) + redirect ("http://www.familysearch.org/Eng/Search/" ++ (fromJust uri)) addfile ./afn.ml hunk ./afn.ml 1 +(* Given an AFN record name, generate html that redirects us to the + family search page for that record. First we retrieve a web page + that contains the recid, then we use that to create the redirect + url. *) + +(* +curl -s 'http://www.familysearch.org/Eng/Search/customsearchresults.asp?date_range_index=0&type=0&LDS=0&event_index=0&date_range=0&file_number=1TF0-QKD&standardize=N&submit=Search&clear=Clear' -> + +af/individual_record.asp?recid=44901677&lds=0&region=%2D1&regionfriendly=&juris1=&juris2=&juris3=&juris4=®ionfriendly=&juris1friendly=&juris2friendly=&juris3friendly=&juris4friendly= + +*) + +let cgivars = ["file_number", ""] + +(* Make a function that returns the value of any cgi variable, + either as passed in the url or the default. *) + +let cgi = + + Cgi.cgiinit (); + +(*Printf.eprintf "List of CGI arguments: