Skip to content
This repository
tree: 228753f70b
Neil Williams July 16, 2012
file 48 lines (39 sloc) 0.939 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
description "send subscriber stats to traffic"

manual
task
stop on reddit-stop or runlevel [016]

nice 10

env DB_HOST=localhost
env DB_PORT=5432
env DB_USER=reddit
env DB_NAME=reddit

env TRAFFIC_HOST=localhost
env TRAFFIC_PORT=5432
env TRAFFIC_USER=reddit
env TRAFFIC_NAME=reddit

script
TEMPFILE=$(mktemp)

cat <<SQL | psql -A -F'|' -t -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME > $TEMPFILE
SELECT
    value,
    CAST(date AS DATE),
    COUNT(*)
FROM
    reddit_rel_srmember r,
    reddit_data_subreddit d
WHERE
    r.name = 'subscriber' AND
    r.date > current_date - interval '1 days' AND
    r.date < current_date - interval '0 days' AND
    d.key = 'name' AND
    r.thing1_id = d.thing_id
GROUP BY
    value,
    CAST(date AS DATE)
;
SQL

cat <<SQL | psql -h $TRAFFIC_HOST -p $TRAFFIC_PORT -U $TRAFFIC_USER -d $TRAFFIC_NAME
\\copy traffic_subscriptions from '$TEMPFILE' with delimiter as '|';
SQL

rm -f $TEMPFILE
end script
Something went wrong with that request. Please try again.