diff options
author | Matthew Somerville <matthew@fury.ukcod.org.uk> | 2011-04-02 01:45:15 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@fury.ukcod.org.uk> | 2011-04-02 01:45:38 +0100 |
commit | 65fd3142a388207262fafeb831f29c12470c6a65 (patch) | |
tree | 16c0ab93d520436b141706b7ce6df21dd0b76c29 | |
parent | 960c1838721cf1f4366fb5c7600aa50b0c9e0c51 (diff) |
Post reports in London to the Report-It API.
-rwxr-xr-x | bin/send-reports | 96 | ||||
-rw-r--r-- | conf/general-example | 4 | ||||
-rw-r--r-- | data/dft.csv | 534 |
3 files changed, 629 insertions, 5 deletions
diff --git a/bin/send-reports b/bin/send-reports index 8e6d2d178..3517f1ee0 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -15,10 +15,12 @@ require 5.8.0; use FindBin; use lib "$FindBin::Bin/../perllib"; use lib "$FindBin::Bin/../commonlib/perllib"; +use Digest::MD5; use Encode; use Error qw(:try); use File::Slurp; use JSON; +use LWP::UserAgent; use LWP::Simple; use CGI; # Trying awkward kludge use CronFns; @@ -53,7 +55,7 @@ my $site = CronFns::site($base_url); my $query = "SELECT id, council, category, title, detail, name, email, phone, used_map, latitude, longitude, (photo is not null) as has_photo, lang, - cobrand, cobrand_data + cobrand, cobrand_data, date_trunc('second', confirmed) as confirmed, postcode FROM problem WHERE state in ('confirmed','fixed') AND whensent IS NULL @@ -86,7 +88,8 @@ foreach my $row (@$unsent) { # Template variables for the email my $email_base_url = Cobrand::base_url_for_emails($cobrand, $cobrand_data); - my %h = map { $_ => $row->{$_} } qw/title detail name email phone category latitude longitude/; + my %h = map { $_ => $row->{$_} } qw/id title detail name email phone category latitude longitude confirmed used_map/; + $h{query} = $row->{postcode}; $h{url} = $email_base_url . '/report/' . $row->{id}; $h{phone_line} = $h{phone} ? _('Phone:') . " $h{phone}\n\n" : ''; if ($row->{has_photo}) { @@ -150,8 +153,10 @@ foreach my $row (@$unsent) { my $name = $areas_info->{$council}->{name}; push @dear, $name; if ($council == 2330) { # E. Hants have a web service - $send_web = 1; + $send_web = 'easthants'; $h{category} = 'Customer Services' if $h{category} eq 'Other'; + } elsif ($areas_info->{$council}->{type} eq 'LBO') { # London + $send_web = 'london'; } else { my ($council_email, $confirmed, $note) = dbh()->selectrow_array( "SELECT email,confirmed,note FROM contacts WHERE deleted='f' @@ -219,7 +224,6 @@ foreach my $row (@$unsent) { } else { push @recips, 'eha@' . mySociety::Config::get('EMAIL_DOMAIN'); } - push @recips, 'matthew@' . mySociety::Config::get('EMAIL_DOMAIN'); } # Special case for this parish council @@ -249,11 +253,15 @@ foreach my $row (@$unsent) { } } - if ($send_web) { + if ($send_web eq 'easthants') { $h{message} = construct_easthants_message(%h); if (!$nomail) { $result *= post_easthants_message(%h); } + } elsif ($send_web eq 'london') { + if (!$nomail) { + $result *= post_london_report(%h); + } } if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { @@ -306,6 +314,8 @@ sub oxfordshire_contact { return "$email\@oxfordshire.gov.uk"; } +# East Hampshire + sub construct_easthants_message { my %h = @_; my $message = ''; @@ -346,6 +356,67 @@ sub post_easthants_message { return $return; } +# London + +sub post_london_report { + my %h = @_; + my $phone = $h{phone}; + my $mobile = ''; + if ($phone =~ /^\s*07/) { + $mobile = $phone; + $phone = ''; + } + my ($first, $last) = $h{name} =~ /^(\S*)(?: (.*))?$/; + my %params = ( + Key => mySociety::Config::get('LONDON_REPORTIT_KEY'), + Signature => Digest::MD5::md5_hex( $h{confirmed} . mySociety::Config::get('LONDON_REPORTIT_SECRET') ), + Type => Utils::london_categories()->{$h{category}}, + RequestDate => $h{confirmed}, + RequestMethod => 'Web', + ExternalId => $h{url}, + 'Customer.Title' => '', + 'Customer.FirstName' => $first, + 'Customer.Surname' => $last, + 'Customer.Email' => $h{email}, + 'Customer.Phone' => $phone, + 'Customer.Mobile' => $mobile, + ); + if ($h{used_map}) { + $params{'Location.Latitude'} = $h{latitude}; + $params{'Location.Longitude'} = $h{longitude}; + } elsif (mySociety::PostcodeUtil::is_valid_postcode($h{query})) { + # Didn't use map, and entered postcode, so use that. + $params{'Location.Postcode'} = $h{query}; + } else { + # Otherwise, lat/lon is all we have, even if it's wrong. + $params{'Location.Latitude'} = $h{latitude}; + $params{'Location.Longitude'} = $h{longitude}; + } + if ($h{has_photo}) { + $params{'Document1.Name'} = 'Photograph'; + $params{'Document1.MimeType'} = 'image/jpeg'; + $params{'Document1.URL'} = $h{image_url}; + $params{'Document1.URLPublic'} = 'true'; + } + my $browser = LWP::UserAgent->new; + my $response = $browser->post( mySociety::Config::get('LONDON_REPORTIT_URL'), \%params ); + my $out = $response->content; + if ($response->code ne 200) { + print "Failed to post $h{id} to London API, response was " . $response->code . " $out\n"; + return 1; + } + my ($id) = $out =~ /<caseid>(.*?)<\/caseid>/; + my ($org) = $out =~ /<organisation>(.*?)<\/organisation>/; + my ($team) = $out =~ /<team>(.*?)<\/team>/; + + $org = london_lookup($org); + dbh()->do("update problem set external_id=?, external_body=?, external_team=? where id=?", {}, + $id, $org, $team, $h{id}); + return 0; +} + +# Nearest things + sub find_closest { my ($row, $latitude, $longitude) = @_; my $str = ''; @@ -374,3 +445,18 @@ sub find_closest { return $str; } +sub london_lookup { + my $org = shift; + my $str = "Unknown ($org)"; + open(FP, "$FindBin::Bin/../data/dft.csv"); + while (<FP>) { + /^(.*?),(.*)/; + if ($org eq $1) { + $str = $2; + last; + } + } + close FP; + return $str; +} + diff --git a/conf/general-example b/conf/general-example index 9da852bb8..b19a6a6bb 100644 --- a/conf/general-example +++ b/conf/general-example @@ -46,6 +46,10 @@ define('OPTION_GEO_CACHE', '/cache/'); define('OPTION_GOOGLE_MAPS_API_KEY', ''); define('OPTION_BING_MAPS_API_KEY', ''); +define('OPTION_LONDON_REPORTIT_URL', ''); +define('OPTION_LONDON_REPORTIT_KEY', ''); +define('OPTION_LONDON_REPORTIT_SECRET', ''); + define('OPTION_MAPIT_URL', 'http://mapit.mysociety.org/'); define('OPTION_MAP_TYPE', 'Tilma::Original::1_10k'); define('OPTION_EVEL_URL', 'http://services.mysociety.org/evel'); diff --git a/data/dft.csv b/data/dft.csv new file mode 100644 index 000000000..0bf1a94d1 --- /dev/null +++ b/data/dft.csv @@ -0,0 +1,534 @@ +Id,Organisation +7249,186k Limited +7246,360 Networks(UK)Ltd +7263,51ยบ Limited +6905,Aberconwy And Colwyn +7235,Abovenet Communications UK Ltd +7082,Affiniti +7297,Airwave Solutions Limited +7302,Aligned Assets Limited +905,Allerdale Borough Council +6983,Amey Highways South East Unit +6982,Amey Highways South West Unit +7025,Andover Cable Services +6805,Anglesey +7026,Anglia Cable +9100,Anglian Water +7303,Ask Controls Ltd +7300,Autodesk Ltd +17,Baa +5060,Barking And Dagenham +5090,Barnet +4405,Barnsley +114,Bath And North East Somerset +7045,Bcm North And East +7043,Bcm South +6980,Bear Scotland Ltd North East Unit +6981,Bear Scotland Ltd North West Unit +235,Bedford UA +225,Bedfordshire +7095,Bell Cablemedia (Wearside) +7096,Bell Cablemedia (Worcester) +5120,Bexley +4605,Birmingham +7028,Birmingham Cable +7198,Birmingham Cable (Wythall) +2372,Blackburn +2373,Blackpool +6910,Blaenau Gwent +4205,Bolton +1250,Bournemouth +9110,Bournemouth And West Hampshire Water +335,Bracknell Forest +4705,Bradford +5150,Brent +6915,Bridgend +1445,Brighton And Hove +116,Bristol +9111,Bristol Waterworks Company +7242,British Gas Connections Ltd +7186,British Oxygen +7089,British Pipeline Agency (Bpa) +7094,British Rail Telecomms +7187,British Waterways Board +7208,Broadband Ventures +7172,Broadcast Satellite Television +7029,Broadland Cablevision +5180,Bromley +7225,Bskyb Telecommunications Services Ltd +30,BT +7171,BT New Towns System +430,Buckinghamshire +7192,Burton-Upon-Trent Cable Comms +4210,Bury +7298,By Design +7319,C2c Services Ltd +70,Cable & Wireless UK +7097,Cable Commmunications Fylde & Wyre +7030,Cable London Plc (Camden) +7099,Cable London Plc (Enfield) +7100,Cable London Plc (Hackney) +7101,Cable London Plc (Haringey) +7103,Cable North West (Central Lancashire) +7052,Cable North West (Merseyside) +7102,Cable North West (North Liverpool) +7104,Cable North West (St Helens) +7105,Cable North West (Wigan) +7173,Cablecom Investments +7032,Cabletel Bedfordshire +7106,Cabletel Central Hertfordshire +7107,Cabletel Hertfordshire +7047,Cabletel Kirklees +7108,Cabletel North Bedfordshire +7109,Cabletel South Wales (Cardiff) +7050,Cabletel South Wales (Newport) +7110,Cabletel South Wales (West Glamorgan) +7111,Cabletel Surrey +7033,Cablevision Wellingborough +7296,Cadcorp +6810,Caernarfonshire And Merionethshire +6920,Caerphilly +4710,Calderdale +7034,Cambridge Cable +9113,Cambridge Water Company +535,Cambridgeshire +5210,Camden +6815,Cardiff +6820,Cardiganshire +6825,Carmarthenshire +7253,Carrier 1 UK Ltd +240,Central Bedfordshire UA +7007,Central Networks +7011,Central Networks +9234,Centro +645,Cheshire +660,Cheshire East UA +665,Cheshire West And Chester UA +9114,Chester Waterworks +9115,Cholderton And District Water +1055,City Of Derby +2465,City Of Leicester +5030,City Of London +7075,City Of London Telecomms +3060,City Of Nottingham +540,City Of Peterborough +1160,City Of Plymouth +1775,City Of Portsmouth +1780,City Of Southampton +3455,City Of Stoke-On-Trent +5990,City Of Westminster +7261,Citylink Telecommunications Ltd +7279,Cityspace Ltd +7112,Comcast Teesside (Darlington) +7113,Comcast Teesside (Teesside) +7035,Comment Cablevision +7058,Comtel (Stafford Comms ) +800,Cornwall +840,Cornwall UA +7036,County Cable Comms +1850,County Of Herefordshire +4610,Coventry +7037,Coventry Cable +7318,Crossrail Ltd +5240,Croydon +900,Cumbria +1350,Darlington +7290,Dclg Firecontrol Project +9138,Dee Valley Water Plc +4900,Defence Estates +6830,Denbighshire +7188,Department For Transport Stats Roads +1050,Derbyshire +1155,Devon +7189,Diamond Cable (Bassetlaw And Ravenshead +7040,Diamond Cable (Grantham) +7114,Diamond Cable (Grimsby) +7115,Diamond Cable (Lincoln) +7203,Diamond Cable (Lincolnshire) +7116,Diamond Cable (Mansfield) +7117,Diamond Cable (Melton Mowbray) +7118,Diamond Cable (Newark) +7119,Diamond Cable (Nottingham) +4410,Doncaster +1245,Dorset +4615,Dudley +1345,Durham +1355,Durham UA +7260,E S Pipelines Ltd +5270,Ealing +7042,East Coast Cable +2001,East Riding Of Yorkshire +1440,East Sussex +7219,Eastern Group Telecoms +7259,Eigernet Ltd +7243,Eircom (UK) Ltd +7325,Eirgrid Plc +7005,Electricity North West Limited +7120,Encom Cable TV & Comms (Dartford) +7121,Encom Cable TV & Comms (Epping Forest) +7122,Encom Cable TV & Comms (Greater London) +7123,Encom Cable TV & Comms (Havering) +7124,Encom Cable TV & Comms (Newham) +7125,Encom Cable TV & Comms (Waltham Forest) +7269,Energetics Electricity Limited +7311,Energetics Gas Limited +7080,Energis Comms +5300,Enfield +7220,Environment Agency +7309,Esp Electricity Limited +1585,Essex +9120,Essex And Suffolk Water +7091,Esso Petroleum Co +7307,Eunetworks Fiber UK Limited +7039,Eurobell (South West) +7044,Eurobell (Sussex) +7126,Eurobell (West Kent) +7282,Exor Corporation Ltd +7127,Fenland Cablevision +7223,Fibernet Ltd +7266,Fibrespan Limited +7305,Fibrespeed Ltd +7206,Fina Pipelines +6835,Flintshire +7234,Flute Ltd +7294,Fulcrum Pipelines Limited +7241,Gamma Telecom Ltd +7231,Gas Transportation Co Ltd +4505,Gateshead +7229,GC Pan European Crossing UK Ltd +7315,Gene Sys Telecommunications Ltd +7237,General Telecommunications Ltd +7304,Geo +7317,Ggp Systems Ltd +7084,Global Communications Holding Ltd +7183,Global Crossing (UK) Telecommunications +1600,Gloucestershire +7207,Government Office (London) +7215,Greater Manchester PTE +3061,Greater Nottingham Light Rapid Transit +5330,Greenwich +7228,GT UK Ltd +7312,H2O Networks +5360,Hackney +7262,Halcrow Group +650,Halton +5390,Hammersmith And Fulham +1770,Hampshire +5420,Haringey +5450,Harrow +724,Hartlepool +9122,Hartlepool Water +5480,Havering +1900,Hertfordshire +7323,Highway Management Scotland Ltd +11,Highways Agency +5510,Hillingdon +7193,Hincley Cable Comms +7285,Historic Scotland +9997,Holeworld Ltd +5540,Hounslow +7077,Hutchinson Microtel +7264,Hutchison 3g Ltd +7245,I-21 Holdings Ltd +7185,ICI Pipelines +7306,Idox Software Ltd +7218,Independent Pipelines Ltd +7281,Independent Power Networks Ltd +7326,Independent Water Networks Ltd +60,Infocus Public Networks Ltd +7291,Innogistic Software Plc +7324,Internal Communication Systems Ltd +7074,Ionica L3 +2114,Isle Of Wight +7251,Isle Of Wight Cable And Telephone Co Ltd +835,Isles Of Scilly +5570,Islington +7289,Jacobs UK Ltd +7174,John Jones +7175,John Sulwyn Evans +7128,Jones Cable Group (Harrogate) +7067,Jones Cable Group (York) +7129,Jones Cable Group Of Leeds +7130,Jones Cable Group South Hertfordshire +5600,Kensington And Chelsea +2275,Kent +9924,Kent Fire And Rescue Service +7308,Key Traffic Systems Ltd +7073,Kingston Comms (Hull) +5630,Kingston Upon Thames +2004,Kingston-Upon-Hull +4715,Kirklees +4305,Knowsley +7267,Kpn Eurorings Bv +7227,Kpn Telecom UK Ltd +7268,Laing Energy Ltd +5660,Lambeth +2371,Lancashire +7277,Lancaster University Network Services +7048,Lcl Cable Comms +4720,Leeds +2460,Leicestershire +7232,Level 3 Communications Ltd +5690,Lewisham +7191,Lichfield Cable Comms +2500,Lincolnshire +4310,Liverpool +7216,London Dockland Development Corp +7009,London Electricity +7210,London Transport +7072,London Underground +7320,Luns Ltd +230,Luton +7283,M6 Concessionaire +18,M6 Toll Motorway (Mel) +7284,M77 Concessionaire +7090,Mainline Pipelines +4215,Manchester +7008,Manweb +7295,Mapinfo Ltd +7288,Mayrise Limited +2280,Medway Towns +50,Mercury +7078,Mercury Pcn +9212,Merseyside Fire Service +6925,Merthyr Tydfil +5720,Merton +7176,Metro Cable TV +9123,Mid Kent Water +9124,Mid Southern Water +13,Mid Wales Trunk Road Agency +734,Middlesborough +7049,Middlesex Cable Comms +7238,Middlesex Cable Ltd +7031,Midland Cable Comms +435,Milton Keynes +7278,Mll Telecom Limited +6840,Monmouthshire +7257,Mowlem Energy Limited +7177,Multichannel Television +7015,National Grid Electricity Transmission +10,National Grid Gas Plc +7217,National Transcommunications Ltd +6930,Neath And Port Talbot +7244,Neoscorp Ltd +7093,Network Rail Infrastructure Ltd +7226,New World Payphones Ltd +4510,Newcastle Upon Tyne +5750,Newham +7275,Newnet Plc +6935,Newport +2600,Norfolk +7293,Norfolk Fire And Rescue Service +7051,North Downs Cable +2002,North East Lincolnshire +9126,North East Water +2003,North Lincolnshire +9127,North Surrey Water +4515,North Tyneside +14,North Wales Trunk Road Agency +121,North West Somerset +9102,North West Water +2745,North Yorkshire +2800,Northamptonshire +7006,Northern Electric +7271,Northern Gas Networks +2900,Northumberland +2935,Northumberland UA +9101,Northumbrian Water +7053,Norwich Cablevision +7222,Nottingham City Heating +3055,Nottinghamshire +7274,Ntl National Networks Ltd +7142,Nynex Cablecomms +7182,O2 (UK) Limited +7092,Oil And Pipeline Agency (Gpss) +4220,Oldham +7321,Olympic Delivery Authority +7258,Omne Telecommunications Ltd +7252,Oncue Telecommunications Ltd +7299,Opal Telecom +7233,Orange Pcs Ltd +7055,Oxford Cable +3100,Oxfordshire +6845,Pembrokeshire +7056,Peterborough Cablevision +7301,Plantech Limited +1255,Poole +7213,Port Of London Authority +9128,Portsmouth Waterworks Company +7316,Powersystems UK Ltd +6850,Powys +345,Reading +5780,Redbridge +728,Redcar And Cleveland +7247,Redstone Network Services Ltd +6940,Rhondda Cynon Taff +5810,Richmond Upon Thames +4225,Rochdale +7322,Rolta UK Limited +7221,Romec Ltd +4415,Rotherham +7214,Royal Parks +7184,Rugby Cement +2470,Rutland +4230,Salford +7179,Salford Cable Television +4620,Sandwell +7180,Sapphire +7273,Scotland Gas Networks Plc +7079,Scottish Hydro-Electric (Comms) +7286,Scottish Natural Heritage +7019,Scottish Power +7287,Scottish Wildlife Trust +4320,Sefton +9103,Severn Trent Water +4420,Sheffield +7209,Sheffield Heat And Power +7070,Shell / BP Pipelines +3235,Shropshire +9922,Shropshire Fire And Rescue Service +3245,Shropshire UA +350,Slough +7211,Slough Heat And Power +4625,Solihull +3300,Somerset +9117,South East Water +119,South Gloucestershire +9129,South Staffordshire Water +4520,South Tyneside +7012,South Wales Electricity +7292,South Wales Fire And Rescue Service +12,South Wales Trunk Road Agency +9105,South West Water +7003,South Western Electricity +9923,South Yorkshire Fire And Rescue Service +9236,South Yorkshire PTE +1590,Southend-On-Sea +7194,Southern East Anglia Cable +7002,Southern Electric +7270,Southern Gas Networks Plc +9104,Southern Water +5840,Southwark +7313,Sse Pipelines Ltd +4315,St Helens +3450,Staffordshire +7059,Starvision Network +4235,Stockport +738,Stockton-On-Tees +9998,Street Managers Without A Specific Code +9999,Street Work Licences +3500,Suffolk +4525,Sunderland +3600,Surrey +5870,Sutton +9118,Sutton And East Surrey Water Plc +9131,Sutton District Water No Longer Operates +6855,Swansea +7145,Sweb Telecoms +3935,Swindon +7060,Swindon Cable +7280,Symology +4240,Tameside +7190,Tamworth Cable Comms +7181,Tawd Valley Cable +7016,Teeside Power +7147,Telecential Comms (Northampton) +7150,Telecential Comms (Rugby) +7151,Telecential Comms (Stratford) +7146,Telecential Comms Northants +7148,Telecential Comms Thames Valley +7149,Telecential Comms Warwickshire +7152,Telecential Comms West Hertfordshire +7240,Telewest Communications Group +3240,Telford And Wrekin +7153,Telford Telecomms +7230,Telia UK Ltd +7085,Telstra European Holdings +9106,Thames Water +7098,The Cable Corporation (Hillingdon) +7066,The Cable Corporation (Windsor) +1595,Thurrock +7224,Thus +7250,T-Mobile (UK)Limited +1165,Torbay +6945,Torfaen +5900,Tower Hamlets +7212,Traffic Director For London +4245,Trafford +20,Transport For London +7087,Transport For London Street Management +7010,UK Power Networks Eastern & London +7004,UK Power Networks South Eastern +7061,United Artists Comms (Avon) +7154,United Artists Comms (Cotswolds) +7156,United Artists Comms (Kingston) +7155,United Artists Comms (London South) +7157,United Artists Comms (Merton) +7158,United Artists Comms (North East) +7159,United Artists Comms (South East) +7255,United Utilities Gas Networks Ltd +7256,United Utilities Gas Pipelines Ltd +7265,Utility Grid Installations Ltd +6950,Vale Of Glamorgan +9133,Veolia Water Central Ltd +9132,Veolia Water East Ltd +7314,Veolia Water Outsoursing Limited +9121,Veolia Water Southeast +7086,Verizon Business +7236,Viatel UK Ltd +7062,Videotron Corporation (Ealing) +7161,Videotron Corporation (Greenwich) +7162,Videotron Corporation (Hammersmith) +7163,Videotron Corporation (Harrow) +7164,Videotron Corporation (Kensington) +7165,Videotron Corporation (Lamberth) +7166,Videotron Corporation (Southampton) +7167,Videotron Corporation (Thamesmead) +7168,Videotron Corporation (Wandsworth) +7169,Videotron Corporation (Winchester) +7205,Videotron Southampton (Totton And Hythe) +7160,Virgin Media +7076,Vodafone Group +7248,Vsnl Telecommunications (UK) Ltd +7254,Vtesse Networks +7276,Vtl (UK) Ltd +4725,Wakefield +7272,Wales & West Utilities Ltd +4630,Walsall +5930,Waltham Forest +5960,Wandsworth +655,Warrington +3700,Warwickshire +16,Welsh Assembly Government +7310,Welsh Highland Railway Construction Ltd +9107,Welsh Water +7064,Wessex Cable +9108,Wessex Water +340,West Berkshire +9137,West Of Scotland Water +3800,West Sussex +9235,West Yorkshire PTE +7065,Westminster Cable Company +4250,Wigan +3930,Wiltshire +3940,Wiltshire UA +355,Windsor And Maidenhead +7239,Windsor Television Ltd +4325,Wirral +360,Wokingham +4635,Wolverhampton +1855,Worcestershire +7081,Worldcom International Ltd +6955,Wrexham +9135,Wrexham Water +2741,York +9136,York Waterworks +7027,Yorkshire Cable Comms +7068,Yorkshire Cable Comms (Bradford) +7041,Yorkshire Cable Comms (Doncaster) +7170,Yorkshire Cable Comms (Halifax) +7057,Yorkshire Cable Comms (Sheffield) +7063,Yorkshire Cable Comms (Wakefield) +7001,Yorkshire Electricity Distribution Ltd +9109,Yorkshire Water +7083,Your Communications Limited |