summaryrefslogtreecommitdiff
path: root/localsmsapps
blob: 09388204b60ca408d6bd71543a82fd04467dcfb8 (plain)
  1. #!/bin/sh
  2. set -e
  3. simpleword() {
  4. echo "$1" | tr '[A-Z]' '[a-z]' | egrep '^[a-z][a-z0-9-]+$' || exit 1
  5. }
  6. urlencode() {
  7. # echo "$1" | perl -e 'use Encode; use URI::Escape; use URI::URL; print URI::URL->new(Encode::decode("utf8", uri_unescape(<STDIN>)))."\n";'
  8. echo "$1" | perl -e 'use URI::URL; print URI::URL->new(<STDIN>)."\n";'
  9. }
  10. phone="$1"; shift
  11. set -- `echo "$@" | perl -e 'use URI::Escape; print lc(uri_unescape(<STDIN>));' | sed -e 's/\+/ /g'`
  12. app=`simpleword "$1"`; shift
  13. case "$app" in
  14. bruger|brugere)
  15. users=`finger -s "$@" | awk '{print $1}' | tail -n +2`
  16. usercount=`echo $users | grep -qc .`
  17. if [ "$usercount" = "1" ]; then
  18. finger -mp "$users" | egrep -v -e '^(Directory|Last)'
  19. else
  20. localuserinfo --mail --custom='%username%: %fullname% <%mailaddress%>' $users
  21. fi
  22. ;;
  23. adresse|adr|nummer|nr|krak|kraks|dgs|gulesider|degulesider)
  24. buffer=
  25. for word in "$@"; do
  26. if [ -n "$word" ]; then
  27. buffer="${buffer:+$buffer+}$word"
  28. fi
  29. done
  30. query="$(urlencode "$buffer")"
  31. wget -q -O- "http://www.krak.dk/Person/Resultat.aspx?Who=$query&WhoOnlySearch=false&Sort=Name" \
  32. | html2text -nobs -width 9999 \
  33. | egrep '^(\*\*.*\*\*|[^[:space:]]+_[^[:space:]]+|[[:space:]]+\* (Tlf|Mobil): .*)$' \
  34. | sed -e 's/^\*\*\*\*\* \(.*\) \*\*\*\*\*$/Person: \1/' -e 's/_/ /g' -e 's/ \+\* \(Tlf\|Mobil\): \+//' \
  35. | egrep -v '^(\*|Flere s|Udvid s)' \
  36. || true
  37. wget -q -O- "http://www.krak.dk/Firma/Resultat.aspx?Query=$query" \
  38. | html2text -nobs -width 9999 \
  39. | egrep '^(\*\*.*\*\*|[^[:space:]]+_[^[:space:]]+|[[:space:]]+\* (Tlf|Mobil): .*)$' \
  40. | sed -e 's/^\*\*\*\*\* \(.*\) \*\*\*\*\*$/Firma: \1/' -e 's/_/ /g' -e 's/ \+\* \(Tlf\|Mobil\): \+//' \
  41. | egrep -v '^(\*|Flere s|Vis kun resultater|Se resultater|\[Se firmaprofil for|Se alle webresultater)' \
  42. || true
  43. ;;
  44. tog|togrejse)
  45. buffer=
  46. viacount=0
  47. for word in "$@"; do
  48. case "$word" in
  49. fra)
  50. buffer="from"
  51. eval $buffer=
  52. ;;
  53. til)
  54. buffer="to"
  55. eval $buffer=
  56. ;;
  57. via)
  58. if [ $viacount -gt 0 ]; then
  59. eval lastviabuffer=\"\${$word$viacount}\"
  60. if [ -z "$lastviabuffer" ]; then
  61. echo >&2 "ERROR: Empty via directive."
  62. exit 1
  63. fi
  64. fi
  65. viacount="$(($viacount+1))"
  66. buffer="$word$viacount"
  67. eval $buffer=
  68. ;;
  69. rejse|st|st.|station)
  70. ;;
  71. *)
  72. case "$buffer" in
  73. from|to|via[123])
  74. eval $buffer=\"\${$buffer:+\$$buffer+}$word\"
  75. ;;
  76. *)
  77. if [ -z "$from" ]; then
  78. from="$word"
  79. elif [ -z "$to" ]; then
  80. to="$word"
  81. else
  82. echo >&2 "ERROR: More than 2 cities mentioned or missing from/to/via directive."
  83. exit 1
  84. fi
  85. esac
  86. ;;
  87. esac
  88. done
  89. # FIXME: Handle more than a single via directive
  90. if [ -n "$from" ] && [ -n "$to" ] && [ $viacount -gt 0 ]; then
  91. url="http://www.rejseplanen.dk/bin/query.exe/mn?queryPageDisplayed=yes&S=$from+station&SBHF=2&Z=$to+station&ZBHF=2&V1=$via1+station&wai=yes&start=Find+rejse&start=Find+rejse"
  92. elif [ -n "$from" ] && [ -n "$to" ]; then
  93. url="http://www.rejseplanen.dk/bin/query.exe/mn?queryPageDisplayed=yes&S=$from+station&SBHF=2&Z=$to+station&ZBHF=2&wai=yes&start=Find+rejse&start=Find+rejse"
  94. else
  95. echo >&2 "ERROR: Too few cities, or missing from/to/via directive."
  96. exit 1
  97. fi
  98. wget -O- "$(urlencode "$url")" \
  99. | html2text -nobs -width 9999 \
  100. | grep '^Din afrejse' | sed -e 's/Din afrejse fra/Afr./' -e 's/Din ankomst til/Ank./' -e 's/ er \(den [0-9.]\+ \)\?kl. / kl. /' -e 's/ er i spor / spor /'
  101. ;;
  102. benzin|benzinpris|diesel|dieselpris)
  103. # Set defaults based on app name
  104. case "$app" in
  105. diesel*) flavor="diesel";;
  106. fyr*|olie) flavor="olie";;
  107. *) flavor="95";;
  108. esac
  109. # Resolve options
  110. for word in "$@"; do
  111. case "$word" in
  112. 92|95|98|diesel|olie|fyringsolie) flavor="$word";;
  113. [[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]) site="$word";;
  114. for|i|oktan|pris|amt) ;;
  115. *) county="$word";;
  116. esac
  117. shift
  118. done
  119. case "$flavor" in
  120. 92) flavorid=1;;
  121. 95) flavorid=2;;
  122. 98) flavorid=3;;
  123. diesel) flavorid=6;;
  124. olie|fyringsolie) flavorid=7;;
  125. esac
  126. case "$county" in
  127. bornh*) countyid=1;;
  128. frederiksborg) countyid=3;;
  129. fyn) countyid=4;;
  130. nordj*) countyid=6;;
  131. ribe) countyid=7;;
  132. ringk*) countyid=8;;
  133. rosk*) countyid=9;;
  134. k?benh*|stork*) countyid=5;;
  135. storstr*) countyid=10;;
  136. s?nderj*) countyid=11;;
  137. vejle) countyid=12;;
  138. vestsj*) countyid=13;;
  139. viborg) countyid=14;;
  140. ?rhus|aarhus) countyid=15;;
  141. esac
  142. # Lookup and compress results
  143. if [ -n "$site" ]; then
  144. wget -O- "http://www.fdmbenzinpriser.dk/wap/ShowStation.aspx?StationID=$site" | html2text -nobs -width 9999
  145. elif [ -n "$countyid" ]; then
  146. wget -O- "http://www.fdmbenzinpriser.dk/wap/AmtpriserPriceList.aspx?OctaneID=$flavorid&AmtID=$countyid" | html2text -nobs -width 9999
  147. else
  148. wget -O- "http://www.fdmbenzinpriser.dk/wap/Landspriser.aspx?ID=$flavorid" | html2text -nobs -width 9999
  149. fi
  150. ;;
  151. esac