Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Output CSV of cobrand counts.

  • Loading branch information...
commit 5c68f3dd87b672967c42669f1e58e7bbb6d21f88 1 parent 374c5db
@dracos dracos authored
View
35 bin/update-cobrand-stats
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+#
+# update-cobrand-stats
+# Copyright (c) 2013 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../perllib";
+use lib "$FindBin::Bin/../commonlib/perllib";
+
+use mySociety::Config;
+BEGIN {
+ mySociety::Config::set_file("$FindBin::Bin/../conf/general");
+}
+use mySociety::DBHandle qw(dbh);
+use FYR; # DB setup
+
+my $st = dbh()->prepare("
+ SELECT cobrand, count(*) as c
+ FROM message
+ WHERE dispatched IS NOT NULL
+ GROUP BY cobrand
+ ORDER BY cobrand
+");
+$st->execute();
+
+open(FP, ">$FindBin::Bin/../../cobrand.csv");
+while (my ($cobrand, $count) = $st->fetchrow_array()) {
+ $cobrand = 'www' unless $cobrand;
+ print FP "$cobrand,$count\n";
+}
+close FP;
View
1  conf/crontab.ugly
@@ -10,6 +10,7 @@ MAILTO=cron-!!(*= $site *)!!@mysociety.org
# Once an hour
44 * * * * !!(*= $user *)!! /data/vhost/!!(*= $vhost *)!!/writetothem/bin/warn-long-queue
+44 * * * * !!(*= $user *)!! /data/vhost/!!(*= $vhost *)!!/writetothem/bin/update-cobrand-stats
# Once a day
!!(* if ($vhost ne 'cities.writetothem.com') { *)!!
View
1  db/schema.sql
@@ -161,6 +161,7 @@ create index message_recipient_email on message(recipient_email);
create index message_lower_recipient_email on message(lower(recipient_email));
-- Group actions look up messages by group
create index message_group_id on message(group_id);
+create index message_cobrand_idx on message(cobrand);
alter table message cluster on message_pkey;
-- message_extradata
View
4 templates/website/index-index.html
@@ -36,7 +36,9 @@
catacombs</a>? &mdash; Nope, just your politicians. Use them. Help
them. Write to them!</small></p>
-<?=$values['num_messages'] ?>
+<? if ($values['num_messages']) {
+ echo "* $values[cobrand] messages: $values[num_messages]";
+} ?>
-->
View
13 web/index.php
@@ -313,7 +313,18 @@ function postcode_form($pc, $cobrand, $cocode, $a_forward, $error_message, $opti
$options = cobrand_postcode_form_options($cobrand);
$form = postcode_form($pc, $cobrand, $cocode, $a_forward, $error_message, $options);
-$num_messages = 0;
+$num_messages = null;
+if ($cobrand && file_exists("../../cobrand.csv")) {
+ if (($handle = fopen("../../cobrand.csv", "r")) !== false) {
+ while (($row = fgetcsv($handle)) !== false) {
+ if ($row[0] === $cobrand) {
+ $num_messages = $row[1];
+ break;
+ }
+ }
+ fclose($handle);
+ }
+}
// Display page
template_draw($template, array(
Please sign in to comment.
Something went wrong with that request. Please try again.