#!/usr/bin/perl -w -I../perllib # flickr.cgi: # Register for Flickr usage, and update photos # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # # $Id: flickr.cgi,v 1.9 2008-10-09 14:20:54 matthew Exp $ use strict; use Standard; use LWP::Simple; use URI::Escape; use mySociety::AuthToken; use mySociety::Email; use mySociety::EmailUtil; use mySociety::Random qw(random_bytes); sub main { my $q = shift; print Page::header($q, title=>'Flickr photo upload'); my $out = ''; if (my $token = $q->param('token')) { my $email = mySociety::AuthToken::retrieve('flickr', $token); if ($email) { my $key = mySociety::Config::get('FLICKR_API'); my $url = 'http://api.flickr.com/services/rest/?method=flickr.people.findByEmail&api_key='.$key.'&find_email=' . uri_escape($email); my $result = get($url); my ($nsid) = $result =~ /nsid="([^"]*)"/; $url = 'http://api.flickr.com/services/rest/?method=flickr.people.getInfo&api_key='.$key.'&user_id=' . uri_escape($nsid); $result = get($url); my ($name) = $result =~ /(.*?)<\/realname>/; $name ||= ''; my $id = dbh()->selectrow_array("select nextval('partial_user_id_seq');"); dbh()->do("insert into partial_user (id, service, nsid, name, email, phone) values (?, 'flickr', ?, ?, ?, '')", {}, $id, $nsid, $name, $email); dbh()->commit(); $out .= $q->p('Thanks for confirming your email address. Please now tag your photos with FixMyStreet (and geo-tag them if you want/can, automatically if possible!) for us to pick them up.'); } else { $out = $q->p(_(<please let us know what went on and we'll look into it. EOF } } elsif (my $email = $q->param('email')) { my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/flickr-confirm"); my %h = (); my $token = mySociety::AuthToken::store('flickr', $email); $h{url} = mySociety::Config::get('BASE_URL') . '/F/' . $token; my $body = mySociety::Email::construct_email({ _template_ => $template, _parameters_ => \%h, To => $email, From => [ mySociety::Config::get('CONTACT_EMAIL'), 'FixMyStreet' ], 'Message-ID' => sprintf('', time(), unpack('h*', random_bytes(5, 1))), }); my $result; $result = mySociety::EmailUtil::send_email($body, mySociety::Config::get('CONTACT_EMAIL'), $email); if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { $out = 'Thanks, we\'ve sent you a confirmation email!'; dbh()->commit(); } else { $out = 'Sorry, something went wrong - very alpha!'; dbh()->rollback(); } } else { $out .= <This feature was added for HackDay London 2007, and might not be of production quality. Please send bug reports to us.

Using the Flickr API, FixMyStreet can utilise all the methods of uploading photos to Flickr to report problems to your council:

  1. Register that you're going to be using Flickr here, so we know to check your photos.
  2. Upload your photo to Flickr, for example via camera phone on location
  3. Tag the photo with FixMyStreet when uploading, or afterwards
  4. Locate the problem on Flickr's map (if you have GPS, this might be done automatically :) )
  5. FixMyStreet will find the photo, and ask you to add/ check the details;
  6. The report is then sent to the council.

To begin, please enter your Flickr email address, both so we know the account to watch and so we can email you when you upload FixMyStreet photos with a link to check and confirm the details:

EOF } print $out; print Page::footer($q); } Page::do_fastcgi(\&main);