Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' into release

  • Loading branch information...
commit 00ac2d8e079bd0466de4e6eb59a95dc076853696 2 parents f4e684d + cce3f84
Dave Cross authored July 27, 2013
6  PoliticalWeb/lib/PoliticalWeb.pm
@@ -29,6 +29,12 @@ get '/about/' => sub {
29 29
   return $page;  
30 30
 };
31 31
 
  32
+get '/register' => sub {
  33
+  my $page = template 'register';
  34
+  cache_page $page;
  35
+  return $page;
  36
+};
  37
+
32 38
 get '/constituency/?' => sub {
33 39
   template 'index', { error => 'That constituency' };
34 40
 };
26  PoliticalWeb/lib/PoliticalWeb/Mp.pm
@@ -82,4 +82,30 @@ sub _get_from_db {
82 82
   });  
83 83
 }
84 84
 
  85
+sub blog {
  86
+  my $self = shift;
  87
+
  88
+  return $self->get_link('blog');
  89
+}
  90
+
  91
+sub blog_feed {
  92
+  my $self = shift;
  93
+
  94
+  return $self->get_link('blogfeed');
  95
+}
  96
+
  97
+
  98
+sub get_link {
  99
+  my $self = shift;
  100
+  my $type = shift;
  101
+
  102
+  my ($link) = $self->db->mp_links({
  103
+    type => $type,
  104
+  });
  105
+
  106
+  return unless $link;
  107
+  return $link->url;
  108
+}
  109
+
  110
+
85 111
 1;
13  PoliticalWeb/views/constituency.tt
@@ -9,6 +9,16 @@ $(document).ready(function () {
9 9
     sort: 'date',
10 10
     sortasc: false
11 11
   });
  12
+[% IF mp.blog -%]
  13
+  $('#blog').rssfeed('[% mp.blog_feed %]', {
  14
+    limit: 10,
  15
+    dateformat: 'timeline',
  16
+    content: false,
  17
+    titletag: 'span',
  18
+    sort: 'date',
  19
+    sortasc: false
  20
+  });
  21
+[% END -%]
12 22
 });
13 23
 </script>
14 24
 [% META title = 'Constituency' -%]
@@ -48,7 +58,7 @@ $(document).ready(function () {
48 58
             <li><a href="http://www.guardian.co.uk/politics/constituency/[% constit.twfy.guardian_id %]">Guardian constituency page</a></li>
49 59
 
50 60
 [% FOREACH link IN mp.db.mp_links -%]
51  
-            <li><a href="[% link.url %]">[% link.description %]</li>
  61
+            <li><a href="[% link.url %]">[% link.description %]</a></li>
52 62
 [% END -%]
53 63
 [% IF mp.twfy.guardian_aristotle_id %]
54 64
             <li><a href="http://www.guardian.co.uk/politics/person/[% mp.twfy.guardian_aristotle_id %]">Guardian MP page</a></li>
@@ -70,7 +80,6 @@ document.write(unescape("%3Cscript src='http://twitterforweb.com/twitterbox.js?u
70 80
 [% END %]
71 81
 [% IF mp.blog -%]
72 82
         <div class="tab-pane" id="blog">
73  
-          Blog here
74 83
         </div>
75 84
 [% END %]
76 85
       </div>
6  PoliticalWeb/views/layouts/main.tt
@@ -26,7 +26,7 @@
26 26
             <li[% IF template.name=="constituencies" %] class="active"[% END %]><a href="/constituencies/">Constituencies</a></li>
27 27
             <li[% IF template.name=="about" %] class="active"[% END %]><a href="/about/">About</a></li>
28 28
           </ul>
29  
-          <ul class="nav pull-right">
  29
+          <ul class="nav pull-right login">
30 30
             <li class="dropdown">
31 31
               <a href="#" class="dropdown-toggle" data-toggle="dropdown">
32 32
                 Share
@@ -40,6 +40,10 @@
40 40
               </ul>
41 41
             </li>
42 42
           </ul>
  43
+          <ul class="nav pull-right">
  44
+            <li><a href="/register">Register</a></li>
  45
+            <li><a href="/login">Log in</a></li>
  46
+          </ul>
43 47
         </div>
44 48
       </div>
45 49
       <div class="span8 offset1">
30  util/get_twitter
... ...
@@ -0,0 +1,30 @@
  1
+#!/usr/bin/perl
  2
+
  3
+use strict;
  4
+use warnings;
  5
+use 5.010;
  6
+
  7
+use Web::Scraper;
  8
+use URI;
  9
+use Data::Dumper;
  10
+
  11
+my $url = 'http://tweetminster.co.uk/mps/page:';
  12
+
  13
+my $twitter = scraper {
  14
+    process 'div.tweeters', 'twitter[]' => scraper {
  15
+    process 'h3', constit => 'TEXT',
  16
+    process '//p[@class="tweetTitle"]/text()', 'name' => 'TEXT',
  17
+    process '//p[@class="tweetTitle"]/text()[last()]', 'username' => 'TEXT',
  18
+  }
  19
+};
  20
+
  21
+my @head = qw[name username constit];
  22
+open my $file, '>', 'constit.csv' or die $!;
  23
+
  24
+foreach (1 .. 41) {
  25
+    say $_;
  26
+    my $res = $twitter->scrape( URI->new($url . $_) );
  27
+    foreach my $t (@{$res->{twitter}}) {
  28
+        print $file join(',', map { s/^\s+//; s/\s+$//; "'$_'" } @$t{@head}), "\n";
  29
+    }
  30
+}
42  util/load_blogs
... ...
@@ -0,0 +1,42 @@
  1
+#!/usr/bin/perl
  2
+
  3
+use strict;
  4
+use warnings;
  5
+use 5.010;
  6
+
  7
+use YAML qw[LoadFile];
  8
+use Data::Dumper;
  9
+
  10
+use FindBin '$Bin';
  11
+use lib "$Bin/../PoliticalWeb/lib";
  12
+use PoliticalWeb::Schema;
  13
+
  14
+my $file = shift || 'perlanetrc';
  15
+
  16
+my $yaml = LoadFile($file);
  17
+
  18
+my $sch = PoliticalWeb::Schema->connect(
  19
+  'dbi:mysql:database=politicalweb', 'politicalweb', 'p0l171c4lw3b',
  20
+);
  21
+my $mp_rs = $sch->resultset('Mp');
  22
+
  23
+foreach my $f (@{$yaml->{feeds}}) {
  24
+  my ($party, $cons, $name) = split /:\s+/, $f->{title};
  25
+  my ($mp) = $mp_rs->search({ mp_name => $name });
  26
+  if ($mp) {
  27
+    warn "Found: $name\n";
  28
+    $mp->add_to_mp_links({
  29
+      description => 'Blog',
  30
+      url         => $f->{web},
  31
+      type        => 'blog',
  32
+    });
  33
+    $mp->add_to_mp_links({
  34
+      description => 'Blog Feed',
  35
+      url         => $f->{url},
  36
+      type        => 'blogfeed',
  37
+    });
  38
+  } else {
  39
+    warn "Can't find $name\n";
  40
+    next;
  41
+  }
  42
+}
32  util/load_twitter
... ...
@@ -0,0 +1,32 @@
  1
+#!/usr/bin/perl
  2
+
  3
+use strict;
  4
+use warnings;
  5
+use 5.010;
  6
+
  7
+use lib 'PoliticalWeb/lib';
  8
+use PoliticalWeb::Schema;
  9
+use Text::ParseWords;
  10
+use Data::Dumper;
  11
+
  12
+open my $file, '<', 'constit.csv' or die $!;
  13
+
  14
+my $sch = PoliticalWeb::Schema->connect(
  15
+  'dbi:mysql:hostname=mag-sol.com:database=politicalweb',
  16
+  'politicalweb', 'p0l171c4lw3b',
  17
+);
  18
+
  19
+my $mp_rs = $sch->resultset('Mp');
  20
+my @cols = qw[name twitter constit];
  21
+while (<$file>) {
  22
+  chomp;
  23
+  my %rec;
  24
+  @rec{@cols} = parse_line(',', 0, $_);
  25
+  say Dumper \%rec;
  26
+
  27
+  if (my ($mp) = $mp_rs->search({mp_name => $rec{name}})) {
  28
+    $mp->update({twitter => $rec{twitter}});
  29
+  } else {
  30
+    warn "No match for $rec{name}\n";
  31
+  }
  32
+}

0 notes on commit 00ac2d8

Please sign in to comment.
Something went wrong with that request. Please try again.