summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot2021-09-01 21:00:57 +0200
committerroot2021-09-01 21:00:57 +0200
commit7feab9b316e9c52f150337411513f6a113065d54 (patch)
tree99b868c7d16659f707eba91936f517dd16e25012
downloadaur-7feab9b316e9c52f150337411513f6a113065d54.tar.gz
Initial commit.
-rw-r--r--.SRCINFO14
-rw-r--r--PKGBUILD44
-rwxr-xr-xvvo-departures67
3 files changed, 125 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..bcb2dadc63db
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,14 @@
+pkgbase = vvo-departures-cli
+ pkgdesc = A command line interface to query real time departure data from stops within the Verkehrsverbund Oberelbe (VVO).
+ pkgver = 20210901+01
+ pkgrel = 1
+ arch = any
+ license = GPL3
+ depends = bash
+ depends = util-linux
+ depends = curl
+ depends = jq
+ source = vvo-departures
+ sha256sums = 17eb29ccfe5dacb7977f3af41bb736ddcb4ecda453385ba1ef5ef132d72e8616
+
+pkgname = vvo-departures-cli
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..e8b545a7c8ac
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,44 @@
+# Maintainer: dreieck
+
+_pkgname=vvo-departures-cli
+pkgname="${_pkgname}"
+pkgver=20210901+01
+pkgrel=1
+pkgdesc="A command line interface to query real time departure data from stops within the Verkehrsverbund Oberelbe (VVO)."
+arch=(
+ "any"
+)
+# Based on the information provided at https://github.com/kiliankoe/vvo/blob/main/documentation/widgets.md.
+# url=""
+license=(
+ 'GPL3'
+)
+depends=(
+ "bash"
+ "util-linux" # for 'column'
+ "curl"
+ "jq"
+)
+makedepends=()
+optdepends=()
+provides=()
+conflicts=()
+source=(
+ "vvo-departures"
+)
+sha256sums=(
+ '17eb29ccfe5dacb7977f3af41bb736ddcb4ecda453385ba1ef5ef132d72e8616'
+)
+
+pkgver() {
+ _ver="$(grep -E '^[[:space:]]*#+[[:space:]]*VERSION:' "${srcdir}/${source[0]}" | head -n1 | awk -F: '{print $2}' | tr '-' '_' | tr -d "\"'[[:space:]]")"
+ if [ -z ${_ver} ]; then
+ error "Could not determine version. Aborting."
+ return 1
+ fi
+ printf '%s' "${_ver}"
+}
+
+package() {
+ install -v -D -m755 "${srcdir}/${source[0]}" "${pkgdir}/usr/bin/vvo-departures"
+}
diff --git a/vvo-departures b/vvo-departures
new file mode 100755
index 000000000000..936f1c3e3fe3
--- /dev/null
+++ b/vvo-departures
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+# VERSION: 20210901+01
+# LICENSE: GNU General Public License v3 or later.
+# Based on the information provided at https://github.com/kiliankoe/vvo/blob/main/documentation/widgets.md.
+
+### Depends on (Executable and package name in Arch Linux):
+# * bash (bash)
+# * curl (curl)
+# * jq (jq)
+# * column (util-linux)
+
+
+## The URL to do the queries against:
+_query_baseurl='http://widgets.vvo-online.de/abfahrtsmonitor/Abfahrten.do'
+
+## A wrapper to URL-encode a string:
+_urlencode() {
+ # urlencode
+ jq -Rr '@uri'
+}
+
+## A wrapper to right-align output:
+_align_right() {
+ column --table --table-right 1 --separator '' --output-separator ''
+}
+
+## If an argument is specified, use it as a stop, otherwise set a default:
+if [ $# -ge 1 ]; then
+ _stop="$1"
+else
+ _stop='Dresden, Hauptbahnhof'
+fi
+
+## Timestamp when we are run:
+_timestring="$(TZ=Europe/Berlin date +%H:%M:%S)"
+
+## URL-encode the input:
+_stop_query="$(_urlencode <<< "${_stop}")"
+
+## Construct the query:
+_query="${_query_baseurl}?hst=${_stop_query}"
+
+## Do the query and save the result:
+_result="$(curl -s -L -X 'GET' "${_query}")"
+
+## Parse the result -- extract the information from the JSON-output, add an explicit zero for 'in zero minutes' (nothing is returned in that case), and put it into a pretty table:
+_result_parsed="$(jq -rc '.[] | .[0]+"|"+.[1]+"|"+(if (.[2] | length) == 0 then "0" else .[2] end)' <<< "${_result}" 2>/dev/null | column --table --table-name "${_stop}" --table-wrap 2 --output-width 96 --table-right 3 --separator '|' --output-separator ' | ')"
+# --table-columns 'L.,-> Ziel,Min' --table-noheadings
+
+## Print the result if it is non-empty, otherwise inform about no result:
+if [ -n "${_result_parsed}" ]; then
+ # # Right-align iff the header is shorter than the table
+ if [ "$(head -n1 <<< "${_result_parsed}" | wc -c)" -gt "$(wc -c <<< "${_stop}: ${_timestring}")" ]; then
+ {
+ printf '%s\n' "${_stop}: ${_timestring}"
+ printf '%s\n' "${_result_parsed}"
+ } | _align_right
+ else
+ printf '%s\n' "${_stop}: ${_timestring}"
+ printf '%s\n' "${_result_parsed}"
+ fi
+else
+ printf '%s\n' "Query for '${_stop}' at ${_timestring} failed".
+ printf '%s\n' "The server returned:"
+ printf '%s\n' "${_result}"
+fi