#!/bin/bash

# A script which ranks my Phlog posts by popularity,
# rather inefficiently.

# I suspect that views of my post about this script
# will be artificially inflated owing to it's prominent
# placement. Also I'm sure the "Judging a Book By It's
# Cover" syndrome will also come into play with an
# entry labeled "How to get a free meal at Olive Garden"
# simply tending to get more hits than one labeled
# "A prose analasys of Renee and Georgette Magrite With
# Their Dog After the War"

# Get todays syslog and isolate Phlog entries which
# in my case all have this form phlog/YYYY.MM.DD
# in an ever-growing hidden raw data file
zgrep pygopherd /var/log/syslog | sed 's@.*/@@' | sed '/20/!d' >> /var/gopher/bin/.topphlogs.raw


# Start formatting the results in phlog/topphlogs.txt
figlet 'Top Phlog Posts' > /var/gopher/phlog/topphlogs.txt
echo '' >> /var/gopher/phlog/topphlogs.txt
echo '   These are the my most looked-at phlog posts sorted by popularity' >> /var/gopher/phlog/topphlogs.txt
echo '' >> /var/gopher/phlog/topphlogs.txt

# Tabulate the raw data, tallying hits by phlog post and sort by highest hits
sort /var/gopher/bin/.topphlogs.raw | uniq -c | sort -nr >> /var/gopher/phlog/topphlogs.txt

# Close up shop and we're done
echo '' >> /var/gopher/phlog/topphlogs.txt
d=$(date)
echo "Current as of $d"  >> /var/gopher/phlog/topphlogs.txt
echo '' >> /var/gopher/phlog/topphlogs.txt

#
#
# This script runs as a cron job at 23:58PM daily
# creating an updated phlog/topphlogs.txt at that time.
# Take it, use it, critique it, ask questions.
# I'll always be a n00b, but I do my best. Enjoy!
# -Tim gopher://tildecow.com
#
#