summaryrefslogtreecommitdiff
path: root/foaf/mkfoaf.sh
blob: 33142da0b845d9cd1bfd347438aacacfbcae743f (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. perl "$bindir/any2rdf.pl" "$tmppath" "$uri" > "$outpath"
  44. rm -f "$tmppath"
  45. foafsign "$outpath"
  46. }
  47. tidyfacebookfoaf() {
  48. inpath="$1"
  49. outpath="$2"
  50. [ -e "$inpath" ] || exit1 "Facebook Exporter RDF file \"$inpath\" does not exist."
  51. perl "$bindir/fbfixup.pl" "$inpath" > "$outpath"
  52. foafsign "$outpath"
  53. }
  54. foafsign() {
  55. inpath="$1"
  56. outpath="$inpath.asc"
  57. gpg -a -o- --detach-sign "$inpath" > "$outpath"
  58. }
  59. paths="$@"
  60. [ -n "$paths" ] || paths=index.ttl
  61. for path in $paths; do
  62. basedir=$(dirname "$path")
  63. turtle2foaf "$path"
  64. linkedin2foaf "$path" || true
  65. # tidyfacebookfoaf "$basedir/facebook/foaf.xml" "$basedir/facebook/index.rdf" || true
  66. foafsign "$basedir/facebook/index.rdf" || true
  67. done