Skip to content

Instantly share code, notes, and snippets.

@pezholio
Last active April 20, 2017 16:06
Show Gist options
  • Save pezholio/3114a6d74d1326ef786bf2592d17c90e to your computer and use it in GitHub Desktop.
Save pezholio/3114a6d74d1326ef786bf2592d17c90e to your computer and use it in GitHub Desktop.
Getting MP information using TheyWorkForYou
var Client = require('node-rest-client').Client;
var constituency = 'Tamworth'; // Or the name of the constituency you want information for
var apiKey = ''; // Add your API key here
var uri = 'https://www.theyworkforyou.com/api/getMP?constituency='+ constituency +'&output=json&key='+ apiKey;
var getUri = function(uri, callback) {
var client = new Client();
client.get(uri, function(data, response) {
callback(data);
return;
});
};
getUri(uri, function(data) {
personID = data.person_id;
console.log(data);
// { member_id: '41282', house: '1', constituency: 'Tamworth', party: 'Conservative', entered_house: '2015-05-08', left_house: '9999-12-31', entered_reason: 'general_election', left_reason: 'still_in_office', person_id: '24747', lastupdate: '2015-05-08 07:37:04', title: '', given_name: 'Christopher', family_name: 'Pincher', full_name: 'Christopher Pincher', url: '/mp/24747/christopher_pincher/tamworth', image: '/images/mpsL/24747.jpeg', image_height: 118, image_width: 78, office: [ { moffice_id: 'uk.parliament.data/Member/4075/GovernmentPost/351', dept: '', position: 'Assistant Whip (HM Treasury)', from_date: '2016-07-17',to_date: '9999-12-31', person: '24747',source: '' } ] }
extra_uri = 'https://www.theyworkforyou.com/api/getMPInfo?id='+ personID +'&output=json&key='+ apiKey;
getUri(extra_uri, function(data) {
console.log(data.eu_ref_stance);
// Leave
console.log(data.wrans_subjects);
// High Speed 2 Railway Line, Waste Disposal, Railways, Railways: Construction, Nuclear Waste
console.log(data.twitter_username);
// ChrisPincher
console.log(data.facebook_page);
// https://facebook.com/ChristopherPincher
});
});
import requests
def get_json(uri):
response = requests.get(uri)
response.raise_for_status()
return response.json()
constituency = 'Tamworth' # Or the name of the constituency you want information for
api_key = '' # Add your API key here
mp_uri = "https://www.theyworkforyou.com/api/getMP?constituency={0}&output=js&key={1}".format(constituency, api_key)
mp_json = get_json(mp_uri)
# {u'left_reason': u'still_in_office', u'left_house': u'9999-12-31', u'office': [{u'moffice_id': u'uk.parliament.data/Member/4075/GovernmentPost/351', u'dept': u'', u'person': u'24747', u'from_date': u'2016-07-17', u'to_date': u'9999-12-31', u'position': u'Assistant Whip (HM Treasury)', u'source': u''}], u'lastupdate': u'2015-05-08 07:37:04', u'url': u'/mp/24747/christopher_pincher/tamworth', u'entered_house': u'2015-05-08', u'image': u'/images/mpsL/24747.jpeg', u'member_id': u'41282', u'image_width': 78, u'family_name': u'Pincher', u'entered_reason': u'general_election', u'image_height': 118, u'title': u'', u'full_name': u'Christopher Pincher', u'house': u'1', u'person_id': u'24747', u'party': u'Conservative', u'constituency': u'Tamworth', u'given_name': u'Christopher'}
# Get useful extra information
person_id = mp_json['person_id']
extra_uri = "https://www.theyworkforyou.com/api/getMPInfo?id={0}&output=js&key={1}".format(person_id, api_key)
extra_json = get_json(extra_uri)
# EU Referendum stance
extra_json['eu_ref_stance']
# u'Leave'
# Topics of interest
extra_json['wrans_subjects']
# u'High Speed 2 Railway Line, Waste Disposal, Railways, Railways: Construction, Nuclear Waste'
# Twitter username
extra_json['twitter_username']
# u'ChrisPincher'
# Facebook Page
extra_json['facebook_page']
# u'https://facebook.com/ChristopherPincher'
require 'json'
require 'net/http'
def get_json(uri)
response = Net::HTTP.get(uri)
JSON.parse(response)
end
constituency = 'Tamworth' # Or the name of the constituency you want information for
api_key = '' # Add your API key here
mp_uri = URI("https://www.theyworkforyou.com/api/getMP?constituency=#{constituency}&output=js&key=#{api_key}")
mp_json = get_json(mp_uri)
#=> {"member_id"=>"41282", "house"=>"1", "constituency"=>"Tamworth", "party"=>"Conservative", "entered_house"=>"2015-05-08", "left_house"=>"9999-12-31", "entered_reason"=>"general_election", "left_reason"=>"still_in_office", "person_id"=>"24747", "lastupdate"=>"2015-05-08 07:37:04", "title"=>"", "given_name"=>"Christopher", "family_name"=>"Pincher", "full_name"=>"Christopher Pincher", "url"=>"/mp/24747/christopher_pincher/tamworth", "image"=>"/images/mpsL/24747.jpeg", "image_height"=>118, "image_width"=>78, "office"=>[{"moffice_id"=>"uk.parliament.data/Member/4075/GovernmentPost/351", "dept"=>"", "position"=>"Assistant Whip (HM Treasury)", "from_date"=>"2016-07-17", "to_date"=>"9999-12-31", "person"=>"24747", "source"=>""}]}
# Get useful extra information
person_id = mp_json['person_id']
extra_uri = URI("https://www.theyworkforyou.com/api/getMPInfo?id=#{person_id}&output=js&key=#{api_key}")
extra_json = get_json(extra_uri)
# EU Referendum stance
extra_json['eu_ref_stance']
#=> "Leave"
# Topics of interest
extra_json['wrans_subjects']
#=> "High Speed 2 Railway Line, Waste Disposal, Railways, Railways: Construction, Nuclear Waste"
# Twitter username
extra_json['twitter_username']
#=> "ChrisPincher"
# Facebook Page
extra_json['facebook_page']
#=> "https://facebook.com/ChristopherPincher"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment