Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added blog support.

  • Loading branch information...
commit cce3f84018063c88d2f0a08625e023ff1afe7244 1 parent d34d36c
@davorg authored
View
6 PoliticalWeb/lib/PoliticalWeb.pm
@@ -29,6 +29,12 @@ get '/about/' => sub {
return $page;
};
+get '/register' => sub {
+ my $page = template 'register';
+ cache_page $page;
+ return $page;
+};
+
get '/constituency/?' => sub {
template 'index', { error => 'That constituency' };
};
View
26 PoliticalWeb/lib/PoliticalWeb/Mp.pm
@@ -82,4 +82,30 @@ sub _get_from_db {
});
}
+sub blog {
+ my $self = shift;
+
+ return $self->get_link('blog');
+}
+
+sub blog_feed {
+ my $self = shift;
+
+ return $self->get_link('blogfeed');
+}
+
+
+sub get_link {
+ my $self = shift;
+ my $type = shift;
+
+ my ($link) = $self->db->mp_links({
+ type => $type,
+ });
+
+ return unless $link;
+ return $link->url;
+}
+
+
1;
View
13 PoliticalWeb/views/constituency.tt
@@ -9,6 +9,16 @@ $(document).ready(function () {
sort: 'date',
sortasc: false
});
+[% IF mp.blog -%]
+ $('#blog').rssfeed('[% mp.blog_feed %]', {
+ limit: 10,
+ dateformat: 'timeline',
+ content: false,
+ titletag: 'span',
+ sort: 'date',
+ sortasc: false
+ });
+[% END -%]
});
</script>
[% META title = 'Constituency' -%]
@@ -48,7 +58,7 @@ $(document).ready(function () {
<li><a href="http://www.guardian.co.uk/politics/constituency/[% constit.twfy.guardian_id %]">Guardian constituency page</a></li>
[% FOREACH link IN mp.db.mp_links -%]
- <li><a href="[% link.url %]">[% link.description %]</li>
+ <li><a href="[% link.url %]">[% link.description %]</a></li>
[% END -%]
[% IF mp.twfy.guardian_aristotle_id %]
<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
[% END %]
[% IF mp.blog -%]
<div class="tab-pane" id="blog">
- Blog here
</div>
[% END %]
</div>
View
6 PoliticalWeb/views/layouts/main.tt
@@ -26,7 +26,7 @@
<li[% IF template.name=="constituencies" %] class="active"[% END %]><a href="/constituencies/">Constituencies</a></li>
<li[% IF template.name=="about" %] class="active"[% END %]><a href="/about/">About</a></li>
</ul>
- <ul class="nav pull-right">
+ <ul class="nav pull-right login">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Share
@@ -40,6 +40,10 @@
</ul>
</li>
</ul>
+ <ul class="nav pull-right">
+ <li><a href="/register">Register</a></li>
+ <li><a href="/login">Log in</a></li>
+ </ul>
</div>
</div>
<div class="span8 offset1">
View
30 util/get_twitter
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use Web::Scraper;
+use URI;
+use Data::Dumper;
+
+my $url = 'http://tweetminster.co.uk/mps/page:';
+
+my $twitter = scraper {
+ process 'div.tweeters', 'twitter[]' => scraper {
+ process 'h3', constit => 'TEXT',
+ process '//p[@class="tweetTitle"]/text()', 'name' => 'TEXT',
+ process '//p[@class="tweetTitle"]/text()[last()]', 'username' => 'TEXT',
+ }
+};
+
+my @head = qw[name username constit];
+open my $file, '>', 'constit.csv' or die $!;
+
+foreach (1 .. 41) {
+ say $_;
+ my $res = $twitter->scrape( URI->new($url . $_) );
+ foreach my $t (@{$res->{twitter}}) {
+ print $file join(',', map { s/^\s+//; s/\s+$//; "'$_'" } @$t{@head}), "\n";
+ }
+}
View
42 util/load_blogs
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use YAML qw[LoadFile];
+use Data::Dumper;
+
+use FindBin '$Bin';
+use lib "$Bin/../PoliticalWeb/lib";
+use PoliticalWeb::Schema;
+
+my $file = shift || 'perlanetrc';
+
+my $yaml = LoadFile($file);
+
+my $sch = PoliticalWeb::Schema->connect(
+ 'dbi:mysql:database=politicalweb', 'politicalweb', 'p0l171c4lw3b',
+);
+my $mp_rs = $sch->resultset('Mp');
+
+foreach my $f (@{$yaml->{feeds}}) {
+ my ($party, $cons, $name) = split /:\s+/, $f->{title};
+ my ($mp) = $mp_rs->search({ mp_name => $name });
+ if ($mp) {
+ warn "Found: $name\n";
+ $mp->add_to_mp_links({
+ description => 'Blog',
+ url => $f->{web},
+ type => 'blog',
+ });
+ $mp->add_to_mp_links({
+ description => 'Blog Feed',
+ url => $f->{url},
+ type => 'blogfeed',
+ });
+ } else {
+ warn "Can't find $name\n";
+ next;
+ }
+}
View
32 util/load_twitter
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use lib 'PoliticalWeb/lib';
+use PoliticalWeb::Schema;
+use Text::ParseWords;
+use Data::Dumper;
+
+open my $file, '<', 'constit.csv' or die $!;
+
+my $sch = PoliticalWeb::Schema->connect(
+ 'dbi:mysql:hostname=mag-sol.com:database=politicalweb',
+ 'politicalweb', 'p0l171c4lw3b',
+);
+
+my $mp_rs = $sch->resultset('Mp');
+my @cols = qw[name twitter constit];
+while (<$file>) {
+ chomp;
+ my %rec;
+ @rec{@cols} = parse_line(',', 0, $_);
+ say Dumper \%rec;
+
+ if (my ($mp) = $mp_rs->search({mp_name => $rec{name}})) {
+ $mp->update({twitter => $rec{twitter}});
+ } else {
+ warn "No match for $rec{name}\n";
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.