diff options
Diffstat (limited to 'bin/import-flickr')
-rwxr-xr-x | bin/import-flickr | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/bin/import-flickr b/bin/import-flickr deleted file mode 100755 index f4a838547..000000000 --- a/bin/import-flickr +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/perl -w - -# import-flickr: -# Get new Flickr photos (uploaded from cameras, hopefully!) -# -# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org. WWW: http://www.mysociety.org -# -# $Id: import-flickr,v 1.9 2008-10-09 17:18:02 matthew Exp $ - -use strict; -require 5.8.0; - -# Horrible boilerplate to set up appropriate library paths. -use FindBin; -use lib "$FindBin::Bin/../perllib"; -use lib "$FindBin::Bin/../commonlib/perllib"; -use File::Slurp; -use LWP::Simple; - -use Utils; -use mySociety::AuthToken; -use mySociety::Config; -use mySociety::DBHandle qw(dbh select_all); -use mySociety::EmailUtil; -use mySociety::Email; - -BEGIN { - mySociety::Config::set_file("$FindBin::Bin/../conf/general"); - mySociety::DBHandle::configure( - Name => mySociety::Config::get('BCI_DB_NAME'), - User => mySociety::Config::get('BCI_DB_USER'), - Password => mySociety::Config::get('BCI_DB_PASS'), - Host => mySociety::Config::get('BCI_DB_HOST', undef), - Port => mySociety::Config::get('BCI_DB_PORT', undef) - ); -} - -my $key = mySociety::Config::get('FLICKR_API'); -my $url = 'http://api.flickr.com/services/rest/?method=flickr.photos.search&tags=fixmystreet&extras=geo,machine_tags&api_key=' . $key . '&user_id='; -my $ids = select_all("select nsid from partial_user where service='flickr'"); -my $result = ''; -foreach (@$ids) { - my $api_lookup = get($url . $_->{nsid}); - next unless $api_lookup; - $result .= $api_lookup; -} - -my %ids; -my $st = select_all('select id from flickr_imported'); -foreach (@$st) { - $ids{$_->{id}} = 1; -} - -# XXX: Hmm... Use format=perl now Cal has added it for me! :) -while ($result =~ /<photo id="([^"]*)" owner="([^"]*)" secret="([^"]*)" server="([^"]*)" farm="([^"]*)" title="([^"]*)".*?latitude="([^"]*)" longitude="([^"]*)".*?machine_tags="([^"]*)"/g) { - my ($id, $owner, $secret, $server, $farm, $title, $latitude, $longitude, $machine) = ($1, $2, $3, $4, $5, $6, $7, $8, $9); - next if $ids{$id}; - if ($machine =~ /geo:/ && !$latitude && !$longitude) { - # Have to fetch raw tags, as otherwise can't tell if it's negative, or how many decimal places - my $url = 'http://api.flickr.com/services/rest/?method=flickr.tags.getListPhoto&api_key=' . $key . '&photo_id=' . $id; - my $tags = get($url); - ($longitude) = $tags =~ /raw="geo:lon=([^"]*)"/i; - ($latitude) = $tags =~ /raw="geo:lat=([^"]*)"/i; - } - my $url = "http://farm$farm.static.flickr.com/$server/".$id.'_'.$secret.'_m.jpg'; - my $image = get($url); - problem_create($id, $owner, $title, $latitude, $longitude, $image); -} - -sub problem_create { - my ($photo_id, $owner, $title, $latitude, $longitude, $image) = @_; - my ($name, $email) = dbh()->selectrow_array("select name, email from partial_user where service='flickr' and nsid=?", {}, $owner); - - # set some defaults - $name ||= ''; - $latitude ||= 0; - $longitude ||= 0; - - my $id = dbh()->selectrow_array("select nextval('problem_id_seq')"); - Utils::workaround_pg_bytea("insert into problem - (id, postcode, latitude, longitude, title, detail, name, - email, phone, photo, state, used_map, anonymous, category, areas) - values - (?, '', ?, ?, ?, '', ?, ?, '', ?, 'partial', 't', 'f', '', '')", 7, - $id, $latitude, $longitude, $title, $name, $email, $image - ); - - dbh()->do('insert into flickr_imported (id, problem_id) values (?, ?)', {}, $photo_id, $id); - - # XXX: Needs to only send email once to user per batch of photos, not one per photo? - my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/flickr-submit"); - my %h = (); - my $token = mySociety::AuthToken::store('partial', $id); - $h{name} = $name; - $h{url} = mySociety::Config::get('BASE_URL') . '/L/' . $token; - - my $body = mySociety::Email::construct_email({ - _template_ => $template, - _parameters_ => \%h, - To => $name ? [ [ $email, $name ] ] : $email, - From => [ mySociety::Config::get('CONTACT_EMAIL'), 'FixMyStreet' ], - }); - - my $result = mySociety::EmailUtil::send_email($body, mySociety::Config::get('CONTACT_EMAIL'), $email); - if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { - dbh()->commit(); - } else { - dbh()->rollback(); - } -} - |