]> git.armaanb.net Git - bin.git/blobdiff - scoop-cgi
rss: implement parallel downloads
[bin.git] / scoop-cgi
index 00241c4667c53fd7718f883f2bec9ecf9bd920e1..a54e15563e0a018abe3edae2311189c76db7c412 100755 (executable)
--- a/scoop-cgi
+++ b/scoop-cgi
@@ -1,5 +1,5 @@
 #!/usr/bin/env sh
-# CGI script to get irc logs from scoop. Powers https://logs.armaanb.net.
+# CGI script to get irc logs from scoop. Powers https://irclogs.armaanb.net.
 
 channel=$(echo "$PATH_INFO" | awk -F / '{print $2}')
 if [ -z "$channel" ]; then
@@ -12,6 +12,7 @@ acheam's IRC logs
 logged channels
 ---------------
 $(awk '{print "  * " $0}' /etc/scoop-cgi/channels)
+$(awk '{print "  * " $0}' /etc/scoop-cgi/logbot)
 
 url format
 ----------
@@ -25,17 +26,27 @@ it's in the public domain!"
                exit 0
 fi
 
-channel=$(grep -x "$channel" /etc/scoop-cgi/channels)
+time=$(echo "$PATH_INFO" | awk -F / -v date="$(date -I)" '
+{($3 != "" ) ? outp = $3 : outp = date; print outp}' | xargs date -I -d)
+
+all=$(cat /etc/scoop-cgi/channels /etc/scoop-cgi/logbot)
+channel=$(echo "$all" | grep -x "$channel")
 if [ -z "$channel" ]; then
                echo "Status: 404"
-               echo "Content-type: text/plain\n"
+               printf "Content-type: text/plain\n\n"
                echo "404. Channel not logged."
                exit 0
 fi
 
-time=$(echo "$PATH_INFO" | awk -F / '{print $3}' | xargs date -I -d)
-db=$(cat /etc/scoop-cgi/database)
-
-echo "Content-type: text/plain\n"
-scoop -d "$db" -p "$channel" -D "${time:-now}" -F "%Y-%m-%d %H:%M:%S" \
-               | awk '{$1=""; print substr($0, 2, length($0) - 1)}'
+printf "Content-type: text/plain\n\n"
+
+if grep -qx "$channel" /etc/scoop-cgi/channels; then
+               db=$(cat /etc/scoop-cgi/database)
+               PAGER=/dev/tty scoop -d "$db" -p "$channel" -D "$time" \
+                                -F "%Y-%m-%d %H:%M:%S" \
+                               | awk '{$1=""; print substr($0, 2, length($0) - 1)}'
+elif grep -qx "$channel" /etc/scoop-cgi/logbot; then
+               awk -v date="$time" 'substr($1, 0, 11) == date {outp = substr($1, 12);
+for (i = 3; i <= NF; i++) outp = outp " " $i; print outp}' \
+                               "/srv/www/scoop-cgi/$channel"
+fi