summaryrefslogtreecommitdiff
path: root/foaf/mkfoaf.sh
blob: 81d3bac07ac5d55b6fa9d906ddd5bc6349991e9a (plain)
  1. #!/bin/sh
  2. # Origin: http://code.google.com/p/lindenb/source/browse/trunk/src/xsl/linkedin2foaf.xsl
  3. # info: http://plindenbaum.blogspot.com/2010/02/linkedinxslt-foaf-people-from.html
  4. set -e
  5. exit1() {
  6. echo "ERROR: $1"
  7. exit 1
  8. }
  9. bindir=$(dirname "$0")
  10. xsltdir="$bindir"
  11. turtle2foaf() {
  12. inpath="$1"
  13. outpath="$2"
  14. [ -n "$outpath" ] || outpath=$(echo "$inpath" | perl -pe 's/\.ttl$/.rdf/ or exit 1') || exit1 "Failed resolving output RDF file from input Turtle file \"$inpath\"."
  15. [ -e "$inpath" ] || exit1 "Turtle file \"$inpath\" does not exist."
  16. # [ ! -e "$outpath" ] || exit1 "RDF file \"$outpath\" already exists."
  17. base="$(perl -ne '/^\@base\s+<(http.+)>/ and print $1 and exit;' "$inpath")" || true
  18. rapper ${base:+-I "$base"} -i turtle -o rdfxml-abbrev "$inpath" > "$outpath"
  19. foafsign "$outpath"
  20. }
  21. linkedin2foaf() {
  22. inpath="$1"
  23. outpath="$2"
  24. [ -n "$outpath" ] || outfile=index.rdf && outpath="$(dirname "$inpath")/linkedin/$outfile"
  25. outdir=$(dirname "$outpath")
  26. tmppath="$outdir/index.html"
  27. [ -e "$inpath" ] || exit1 "Turtle file \"$inpath\" does not exist."
  28. [ ! -e "$tmppath" ] || exit1 "Tempfile \"$tmppath\" already exists."
  29. # TODO: support homepage as fallback for accountName
  30. # id=$(perl -0 -ne '/foaf:accountServiceHomepage\s+<http:\/\/www.linkedin.com\/>\s+;\s+foaf:(?:homepage\s+<(?=http)|accountName\s+")([^<"\s]+)/ and print $1 and exit;' "$inpath") #'
  31. # id=$(perl -0 -ne '/^:me.*?foaf:accountServiceHomepage\s+<http:\/\/www.linkedin.com\/>\s+;\s+foaf:accountName\s+"([^<"\s]+)/ms and print $1 and exit;' "$inpath") #'
  32. # id=62345396
  33. id=jonassm
  34. [ -n "$id" ] || exit1 "Failed to resolve LinkedIn account name."
  35. uri="http://www.linkedin.com/in/$id"
  36. mkdir -p "$outdir"
  37. # work around unescaped &'s in linkedin pages
  38. # xsltproc --html "$bindir/linkedin2foaf.xsl" "$uri" > "$outpath"
  39. wget -q -O "$tmppath" "$uri"
  40. # perl -i -pe 's/&([a-zA-Z0-9]+=|\s)/&amp;$1/g' "$tmppath"
  41. # xsltproc --html "$xsltdir/linkedin2foaf.xsl" "$tmppath" > "$outpath"
  42. perl "$bindir/linkedin2rdf.pl" "$tmppath" "$uri" > "$outpath"
  43. rm -f "$tmppath"
  44. foafsign "$outpath"
  45. }
  46. tidyfacebookfoaf() {
  47. inpath="$1"
  48. outpath="$2"
  49. [ -e "$inpath" ] || exit1 "Facebook Exporter RDF file \"$inpath\" does not exist."
  50. perl "$bindir/fbfixup.pl" "$inpath" > "$outpath"
  51. foafsign "$outpath"
  52. }
  53. foafsign() {
  54. inpath="$1"
  55. outpath="${inpath}_sig.pgp"
  56. gpg -a -o- --detach-sign "$inpath" > "$outpath"
  57. }
  58. paths="$@"
  59. [ -n "$paths" ] || paths=index.ttl
  60. for path in $paths; do
  61. basedir=$(dirname "$path")
  62. turtle2foaf "$path"
  63. linkedin2foaf "$path" || true
  64. # tidyfacebookfoaf "$basedir/facebook/foaf.xml" "$basedir/facebook/index.rdf" || true
  65. foafsign "$basedir/facebook/index.rdf" || true
  66. done