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