This notebook describes a basic converational UI for working with the UK Companies House API.
To work with the API, you will need to get an API key:
CH_API_TOKEN='YOUR_TOKEN'
import urllib2, base64, json
from urllib import urlencode
#Inspired by http://stackoverflow.com/a/2955687/454773
def ch_request(CH_API_TOKEN,url,args=None):
if args is not None:
url='{}?{}'.format(url,urlencode(args))
request = urllib2.Request(url)
# You need the replace to handle encodestring adding a trailing newline
# (https://docs.python.org/2/library/base64.html#base64.encodestring)
base64string = base64.encodestring('%s:' % (CH_API_TOKEN)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
return json.loads(result.read())
def ch_searchCompanies(q,n=50,start_index='',typ=None):
#typ: exact, contains, None,
url= 'https://api.companieshouse.gov.uk/search/companies'
properties={'q':q,'items_per_page':n,'start_index':''}
c=ch_request(CH_API_TOKEN,url,properties)
if typ=='contains':
c['items']=[i for i in c['items'] if q.lower() in i['title'].lower()]
elif typ=='exact':
c['items']=[i for i in c['items'] if q.lower() == i['title'].lower()]
return c
ch_searchCompanies('FutureLearn',5,typ='contains')
{u'items': [{u'address': {u'address_line_1': u'CHAMBERS BUILDING', u'address_line_2': u'WALTON HALL', u'locality': u'MILTON KEYNES', u'po_box': u'77', u'postal_code': u'MK7 6BT'}, u'company_number': u'08324083', u'company_status': u'active', u'company_type': u'ltd', u'date_of_creation': u'2012-12-10', u'description': u'08324083 - Incorporated on 10 December 2012', u'description_identifier': [u'incorporated-on'], u'kind': u'searchresults#company', u'links': {u'self': u'/company/08324083'}, u'matches': {u'title': [1, 11]}, u'snippet': u'PO Box 77, Chambers Building, Walton Hall, Milton Keynes, MK7 6BT', u'title': u'FUTURELEARN LIMITED'}], u'items_per_page': 5, u'kind': u'search#companies', u'page_number': 1, u'start_index': 0, u'total_results': 9}
def ch_getCompany(cn):
url="https://api.companieshouse.gov.uk/company/{}".format(cn)
return ch_request(CH_API_TOKEN,url)
ch_getCompany('08324083')
{u'accounts': {u'accounting_reference_date': {u'day': u'31', u'month': u'07'}, u'last_accounts': {u'made_up_to': u'2014-07-31', u'type': u'small'}, u'next_due': u'2016-04-30', u'next_made_up_to': u'2015-07-31', u'overdue': False}, u'annual_return': {u'last_made_up_to': u'2015-12-10', u'next_due': u'2017-01-07', u'next_made_up_to': u'2016-12-10', u'overdue': False}, u'can_file': True, u'company_name': u'FUTURELEARN LIMITED', u'company_number': u'08324083', u'company_status': u'active', u'date_of_creation': u'2012-12-10', u'etag': u'd2e26c313c568e06e1c9e09687967117e8e56a64', u'has_been_liquidated': False, u'has_charges': False, u'has_insolvency_history': False, u'jurisdiction': u'england-wales', u'last_full_members_list_date': u'2015-12-10', u'registered_office_address': {u'address_line_1': u'Chambers Building', u'address_line_2': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT'}, u'sic_codes': [u'85590'], u'type': u'ltd', u'undeliverable_registered_office_address': False}
def ch_getCompanyOfficers(cn,typ='all'):
#typ: all, current, previous
url="https://api.companieshouse.gov.uk/company/{}/officers".format(cn)
co=ch_request(CH_API_TOKEN,url)
if typ=='current':
co['items']=[i for i in co['items'] if 'resigned_on' not in i]
#should possibly check here that len(co['items'])==co['active_count'] ?
elif typ=='previous':
co['items']=[i for i in co['items'] if 'resigned_on' in i]
return co
ch_getCompanyOfficers('08324083',typ='current')
{u'active_count': 10, u'etag': u'32a2b43341b32b985d8bc403814435d42b66ed31', u'items': [{u'address': {u'address_line_1': u'Walton Hall', u'country': u'England', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2013-01-21', u'links': {u'officer': {u'appointments': u'/officers/J5e5BeNBhETllEoclj3Ntp4FSOU/appointments'}}, u'name': u'CHEYNE, Brian', u'officer_role': u'secretary'}, {u'address': {u'address_line_1': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2014-12-17', u'country_of_residence': u'England', u'date_of_birth': {u'month': 7, u'year': 1945}, u'links': {u'officer': {u'appointments': u'/officers/KV_yls-40Oup2XIoeId7sy0b8pA/appointments'}}, u'name': u'BASSINDALE, Alan Richard, Professor', u'nationality': u'British', u'occupation': u'Pro-Vice-Chancellor', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2014-03-31', u'country_of_residence': u'United Kingdom', u'date_of_birth': {u'month': 6, u'year': 1972}, u'links': {u'officer': {u'appointments': u'/officers/5qL7dtE5Vz9LqWrE6AIGqK-4_zk/appointments'}}, u'name': u'COOKE, Justin Alex Edward', u'nationality': u'British', u'occupation': u'Chief Executive', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Walton Hall', u'country': u'England', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2013-01-21', u'country_of_residence': u'United Kingdom', u'date_of_birth': {u'month': 9, u'year': 1956}, u'links': {u'officer': {u'appointments': u'/officers/eJZIFS2nbSHZkvCgtaufbJWaJ_s/appointments'}}, u'name': u'HEDGES, Miles Stuart', u'nationality': u'British', u'occupation': u'Finance Director', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2016-01-26', u'country_of_residence': u'England', u'date_of_birth': {u'month': 2, u'year': 1970}, u'links': {u'officer': {u'appointments': u'/officers/M4tn3QS93s_crb8c9UAaRr8SnA4/appointments'}}, u'name': u'HILL, Steven John', u'nationality': u'British', u'occupation': u'Director, External Engagement', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2015-06-11', u'country_of_residence': u'England', u'date_of_birth': {u'month': 10, u'year': 1959}, u'links': {u'officer': {u'appointments': u'/officers/MeeK3ZOQPi2M8QSJ53tVEulX_aQ/appointments'}}, u'name': u'HORROCKS, Peter', u'nationality': u'British', u'occupation': u'Vice Chancellor', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2015-12-03', u'country_of_residence': u'United Kingdom', u'date_of_birth': {u'month': 9, u'year': 1958}, u'links': {u'officer': {u'appointments': u'/officers/Tyk3KEbbpwXQ0RJ-h7fRJCf08B4/appointments'}}, u'name': u'MACPHERSON, Agnes Lawrie Addie Shonaig', u'nationality': u'British', u'occupation': u'N/A', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2014-03-31', u'country_of_residence': u'United Kingdom', u'date_of_birth': {u'month': 8, u'year': 1950}, u'links': {u'officer': {u'appointments': u'/officers/TpIhJAMMa2Cz_DIwBKWhWFUEV5Q/appointments'}}, u'name': u'NEALE, Frank Leslie George', u'nationality': u'British', u'occupation': u'Business Coach', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Walton Hall', u'country': u'England', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2013-03-25', u'country_of_residence': u'England', u'date_of_birth': {u'month': 7, u'year': 1969}, u'links': {u'officer': {u'appointments': u'/officers/9Lc-6eIIC21nNFTERPV3aWGaKSQ/appointments'}}, u'name': u'NELSON, Simon Jonathan', u'nationality': u'British', u'occupation': u'Ceo', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2014-06-09', u'country_of_residence': u'United Kingdom', u'date_of_birth': {u'month': 9, u'year': 1965}, u'links': {u'officer': {u'appointments': u'/officers/VQCcxNXNfojXKIX27wlG3o46nFI/appointments'}}, u'name': u'TYNAN, Belinda Robyn, Professor', u'nationality': u'Australian', u'occupation': u'Pro Vice-Chancellor', u'officer_role': u'director'}], u'items_per_page': 35, u'kind': u'officer-list', u'links': {u'self': u'/company/08324083/appointments'}, u'resigned_count': 3, u'start_index': 0, u'total_results': 13}
def ch_getAppointments(slug,location=None):
if len(slug.split('/'))==1:
slug='/officers/{}/appointments'.format(slug)
url= 'https://api.companieshouse.gov.uk{}'.format(slug)
a=ch_request(CH_API_TOKEN,url)
if location is not None:
a['items']=[i for i in a['items'] if location.lower() in i['address']['locality'].lower()]
return a
ch_getAppointments('/officers/Tyk3KEbbpwXQ0RJ-h7fRJCf08B4/appointments')
{u'date_of_birth': {u'month': 9, u'year': 1958}, u'etag': u'd343189c1737e8c71f3a8a4a4ff1462ccb4e9479', u'is_corporate_officer': False, u'items': [{u'address': {u'address_line_1': u'Walton Hall', u'locality': u'Milton Keynes', u'po_box': u'77', u'postal_code': u'MK7 6BT', u'premises': u'Chambers Building'}, u'appointed_on': u'2015-12-03', u'appointed_to': {u'company_name': u'FUTURELEARN LIMITED', u'company_number': u'08324083', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/08324083'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'N/A', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Lochcote', u'country': u'Scotland', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'premises': u'.', u'region': u'West Lothian'}, u'appointed_on': u'2015-11-18', u'appointed_to': {u'company_name': u'EDINBURGH BUSINESS SCHOOL', u'company_number': u'SC173556', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC173556'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Company Director', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'100 Renfrew Street', u'address_line_2': u'Glasgow', u'postal_code': u'G2 3DB'}, u'appointed_on': u'2015-09-30', u'appointed_to': {u'company_name': u'ROYAL CONSERVATOIRE OF SCOTLAND', u'company_number': u'SC004703', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC004703'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'29 Constitution Street', u'locality': u'Edinburgh', u'postal_code': u'EH6 7BS', u'premises': u'Creative Exchange'}, u'appointed_on': u'2015-02-11', u'appointed_to': {u'company_name': u"EUAN'S GUIDE", u'company_number': u'SC497565', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC497565'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Bath Street', u'country': u'United Kingdom', u'locality': u'Glasgow', u'postal_code': u'G2 4TB', u'premises': u'152'}, u'appointed_on': u'2013-05-23', u'appointed_to': {u'company_name': u'KINTAIL TRUSTEES LIMITED', u'company_number': u'SC428674', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC428674'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Non Executive Director', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Royal Lyceum Theatre Co', u'address_line_2': u'Grindlay Street', u'locality': u'Edinburgh', u'postal_code': u'EH3 9AX', u'region': u'Lothian'}, u'appointed_on': u'2012-11-02', u'appointed_to': {u'company_name': u'THE ROYAL LYCEUM THEATRE COMPANY LIMITED', u'company_number': u'SC062065', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC062065'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Company Director', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2005-04-06', u'appointed_to': {u'company_name': u'LOCHCOTE ASSET MANAGEMENT LIMITED', u'company_number': u'SC212242', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC212242'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2003-11-04', u'appointed_to': {u'company_name': u'SHARING STORIES LIMITED', u'company_number': u'SC258451', u'company_status': u'dissolved'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC258451'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2003-10-29', u'appointed_to': {u'company_name': u'SHARING STORIES LIMITED', u'company_number': u'SC258451', u'company_status': u'dissolved'}, u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC258451'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'officer_role': u'secretary'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_before': u'1992-02-01', u'appointed_to': {u'company_name': u'BUSWELL WITH MACPHERSON LIMITED', u'company_number': u'02116691', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'is_pre_1992_appointment': True, u'links': {u'company': u'/company/02116691'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_before': u'1992-02-01', u'appointed_to': {u'company_name': u'BUSWELL WITH MACPHERSON LIMITED', u'company_number': u'02116691', u'company_status': u'active'}, u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'is_pre_1992_appointment': True, u'links': {u'company': u'/company/02116691'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'secretary'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2007-06-13', u'appointed_to': {u'company_name': u'THE ROYAL EDINBURGH MILITARY TATTOO LIMITED', u'company_number': u'SC128255', u'company_status': u'active'}, u'country_of_residence': u'Great Britain', u'links': {u'company': u'/company/SC128255'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON, CBE, FRSE DUNIV', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON, CBE, FRSE DUNIV', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director', u'resigned_on': u'2015-10-31'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2007-06-13', u'appointed_to': {u'company_name': u'THE ROYAL EDINBURGH MILITARY TATTOO (CHARITIES) LIMITED', u'company_number': u'SC108857', u'company_status': u'active'}, u'country_of_residence': u'Scotland', u'links': {u'company': u'/company/SC108857'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON, CBE, FRSE', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON, CBE, FRSE', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director', u'resigned_on': u'2015-10-31'}, {u'address': {u'address_line_1': u'Market Street', u'locality': u'Edinburgh', u'postal_code': u'EH1 1QB', u'premises': u'32'}, u'appointed_on': u'2015-01-21', u'appointed_to': {u'company_name': u'THE ROYAL EDINBURGH MILITARY TATTOO (INTERNATIONAL) LIMITED', u'company_number': u'SC495673', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC495673'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Non Executive Director', u'officer_role': u'director', u'resigned_on': u'2015-10-30'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2004-08-25', u'appointed_to': {u'company_name': u'EDINBURGH INTERNATIONAL CONFERENCE CENTRE LIMITED', u'company_number': u'SC131773', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC131773'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Company Director', u'officer_role': u'director', u'resigned_on': u'2014-09-30'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2006-01-27', u'appointed_to': {u'company_name': u"THE PRINCE'S TRUST YOUTH BUSINESS SCOTLAND", u'company_number': u'SC097426', u'company_status': u'dissolved'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC097426'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director', u'resigned_on': u'2012-04-20'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2006-02-10', u'appointed_to': {u'company_name': u'NATIONALTRUST FOR SCOTLAND ENTERPRISES LTD.', u'company_number': u'SC095585', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC095585'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director', u'resigned_on': u'2010-01-29'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'1999-12-14', u'appointed_to': {u'company_name': u'THE SCOTTISH COUNCIL FOR DEVELOPMENT AND INDUSTRY', u'company_number': u'SC024724', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC024724'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2009-12-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2000-02-08', u'appointed_to': {u'company_name': u'EDINBURGH INTERNATIONAL FILM COUNCIL', u'company_number': u'SC131524', u'company_status': u'dissolved'}, u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC131524'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'secretary', u'resigned_on': u'2009-08-12'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2000-02-08', u'appointed_to': {u'company_name': u'THE EDINBURGH INTERNATIONAL FILM FESTIVAL LIMITED', u'company_number': u'SC132453', u'company_status': u'active'}, u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC132453'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'secretary', u'resigned_on': u'2009-08-12'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2000-02-08', u'appointed_to': {u'company_name': u'THE EDINBURGH INTERNATIONAL FILM FESTIVAL LIMITED', u'company_number': u'SC132453', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC132453'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2009-06-30'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2003-11-01', u'appointed_to': {u'company_name': u'ITI SCOTLAND LIMITED', u'company_number': u'SC251900', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC251900'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2009-01-31'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2005-10-01', u'appointed_to': {u'company_name': u'STRATHTAY VENTURES LIMITED', u'company_number': u'SC171237', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC171237'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director', u'resigned_on': u'2008-09-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2005-10-01', u'appointed_to': {u'company_name': u'BRAVEHEART INVESTMENT GROUP PLC', u'company_number': u'SC247376', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC247376'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Director', u'officer_role': u'director', u'resigned_on': u'2008-09-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_before': u'1992-01-14', u'appointed_to': {u'company_name': u'MACPHERSON COACHES LIMITED', u'company_number': u'01930463', u'company_status': u'active'}, u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'is_pre_1992_appointment': True, u'links': {u'company': u'/company/01930463'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'officer_role': u'secretary', u'resigned_on': u'2006-05-08'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2004-06-09', u'appointed_to': {u'company_name': u'BRITISH CHAMBERS OF COMMERCE', u'company_number': u'00009635', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/00009635'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2006-03-03'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2000-02-08', u'appointed_to': {u'company_name': u'EDINBURGH INTERNATIONAL FILM COUNCIL', u'company_number': u'SC131524', u'company_status': u'dissolved'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC131524'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2005-01-05'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'1998-04-01', u'appointed_to': {u'company_name': u'CALEDONIAN PACIFIC TRUSTEES LIMITED', u'company_number': u'SC102953', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC102953'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2004-12-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'1992-08-19', u'appointed_to': {u'company_name': u'MD SECRETARIES LIMITED', u'company_number': u'SC104964', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC104964'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2004-12-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'1998-04-01', u'appointed_to': {u'company_name': u'PINSENT MASONS SECRETARIES (EDINBURGH) LIMITED', u'company_number': u'SC109629', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC109629'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2004-12-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2001-10-30', u'appointed_to': {u'company_name': u'M. G. D. PROPERTY COMPANY LIMITED', u'company_number': u'SC044097', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC044097'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2004-12-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'1992-08-19', u'appointed_to': {u'company_name': u'MD DIRECTORS LIMITED', u'company_number': u'SC104963', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC104963'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'director', u'resigned_on': u'2004-12-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'1998-04-01', u'appointed_to': {u'company_name': u'CALEDONIAN PACIFIC TRUSTEES LIMITED', u'company_number': u'SC102953', u'company_status': u'active'}, u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC102953'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'secretary', u'resigned_on': u'2004-12-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'1998-04-01', u'appointed_to': {u'company_name': u'PINSENT MASONS SECRETARIES (EDINBURGH) LIMITED', u'company_number': u'SC109629', u'company_status': u'active'}, u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC109629'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Solicitor', u'officer_role': u'secretary', u'resigned_on': u'2004-12-10'}, {u'address': {u'address_line_1': u'Lochcote', u'locality': u'Linlithgow', u'postal_code': u'EH49 6QE', u'region': u'West Lothian'}, u'appointed_on': u'2002-07-18', u'appointed_to': {u'company_name': u'THE EAST LOTHIAN CHAMBER OF COMMERCE LIMITED', u'company_number': u'SC174639', u'company_status': u'active'}, u'country_of_residence': u'United Kingdom', u'former_names': [{u'surname': u'SHONAIG MACPHERSON'}], u'links': {u'company': u'/company/SC174639'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'name_elements': {u'forename': u'Agnes', u'honours': u'CBE FRSE', u'other_forenames': u'Lawrie Addie Shonaig', u'surname': u'MACPHERSON', u'title': u'Ms'}, u'nationality': u'British', u'occupation': u'Lawyer', u'officer_role': u'director', u'resigned_on': u'2004-07-02'}], u'items_per_page': 35, u'kind': u'personal-appointment', u'links': {u'self': u'/officers/Tyk3KEbbpwXQ0RJ-h7fRJCf08B4/appointments'}, u'name': u'Agnes Lawrie Addie Shonaig MACPHERSON', u'start_index': 0, u'total_results': 54}
def ch_searchOfficers(q,n=50,start_index='',company=''):
url= 'https://api.companieshouse.gov.uk/search/officers'
properties={'q':q,'items_per_page':n,'start_index':start_index}
o=ch_request(CH_API_TOKEN,url,properties)
if company != '':
o['items'] = [j for j in o['items'] for i in ch_getAppointments(j['links']['self'])['items'] if company.lower() in i['appointed_to']['company_name'].lower()]
return o
ch_searchOfficers('Peter Horrocks',n=5,company='Futurelearn')
{u'items': [{u'address': {u'address_line_1': u'Walton Hall', u'address_line_2': u'Milton Keynes', u'locality': u'Buckinghamshire', u'postal_code': u'MK7 6AA'}, u'appointment_count': 2, u'date_of_birth': {u'month': 10, u'year': 1959}, u'description': u'Total number of appointments 2 - Born October 1959', u'description_identifiers': [u'appointment-count', u'born-on'], u'kind': u'searchresults#officer', u'links': {u'self': u'/officers/MeeK3ZOQPi2M8QSJ53tVEulX_aQ/appointments'}, u'matches': {u'title': [1, 5, 7, 14]}, u'snippet': u'Walton Hall, Milton Keynes, Buckinghamshire, MK7 6AA', u'title': u'Peter HORROCKS'}], u'items_per_page': 5, u'kind': u'search#officers', u'page_number': 1, u'start_index': 0, u'total_results': 218284}
The Companies House API doesn't provide a very powerful search facility, but we can finesse our own by loading the scattergun results from the Companies House API into an in memory database and then querying again.
import sqlite3
db = sqlite3.connect(":memory:")
c = db.cursor()
c.execute('''create table directors
(id text primary key,
dob integer,
addr text,
title text,
cnt integer,
descr text)''')
<sqlite3.Cursor at 0x10731db20>
x=[{'id':p['links']['self'],
'dob':p['date_of_birth']['year'] if 'date_of_birth' in p else None,
'addr':p['snippet'],
'title':p['title'],
'cnt':p['appointment_count'],
'descr':p['description']} for p in o['items']]
c.executemany('INSERT INTO directors (id, dob,addr,title,cnt,descr) '
'VALUES (:id,:dob,:addr,:title,:cnt,:descr)', x)
<sqlite3.Cursor at 0x10731db20>
for r in c.execute('select * from directors where title="Peter Horrocks" COLLATE NOCASE order by cnt desc'):
print(r)
(u'/officers/fx_cgCEl1nfMR8pXlcqlemKowxs/appointments', 1960, u'26 Stretton Road, Greenmount, Bury, Lancashire, BL8 4DF', u'Peter HORROCKS', 4, u'Total number of appointments 4 - Born April 1960') (u'/officers/pHhQOg0gUt8V-8CWgKMx8P3tEdQ/appointments', 1953, u'Orchard Lea, Old Bury Road, Alpheton, Sudbury, Suffolk, United Kingdom, CO10 9BT', u'Peter HORROCKS', 3, u'Total number of appointments 3 - Born October 1953') (u'/officers/LnKbanK0iJ7Ovo2SOdySBgL8PVM/appointments', 1942, u'Mon Reve, Manchester Road, Blackrod, Bolton, Lancashire, BL6 5LS', u'Peter HORROCKS', 2, u'Total number of appointments 2 - Born January 1942') (u'/officers/MeeK3ZOQPi2M8QSJ53tVEulX_aQ/appointments', 1959, u'Walton Hall, Milton Keynes, Buckinghamshire, MK7 6AA', u'Peter HORROCKS', 2, u'Total number of appointments 2 - Born October 1959') (u'/officers/gCQeLQmnBol7dzvRUwSRzcQESvk/appointments', 1945, u'Redmayne Hall, Little Urswick, Ulverston, Cumbria, LA12 0PL', u'Peter HORROCKS', 2, u'Total number of appointments 2 - Born November 1945') (u'/officers/MPIj14JtbOLR8V6HpQtRyufXmkA/appointments', 1955, u'Mansion House, Manchester Road, Altrincham, Cheshire, England, WA14 4RW', u'Peter HORROCKS', 1, u'Total number of appointments 1 - Born November 1955') (u'/officers/FPplxHepRVKyUAwp0Anww4t5EOc/appointments', 1959, u'Fell View Cottage, Garrs End Lane, Grassington, Skipton, North Yorkshire, United Kingdom, BD23 5BB', u'Peter HORROCKS', 1, u'Total number of appointments 1 - Born November 1959') (u'/officers/d1ZtdLMnQq4UhtIxyVhwPplDD44/appointments', 1946, u'Beacon House, Brambleside, Bellbrook Park Uckfield, East Sussex, TN22 1PL', u'Peter HORROCKS', 1, u'Total number of appointments 1 - Born August 1946') (u'/officers/4-hR6E9P_XwBWlCOvEX3ulVrLxQ/appointments', 1960, u'82 Holme Avenue, Bury, Lancashire, United Kingdom, BL8 1HW', u'Peter HORROCKS', 1, u'Total number of appointments 1 - Born April 1960') (u'/officers/lvJfGf3Z0YqlE0Vt0GZE_DjC7_A/appointments', 1937, u'22 Bealey Drive, Bury, Lancashire, BL9 9NA', u'Peter HORROCKS', 1, u'Total number of appointments 1 - Born February 1937') (u'/officers/SV2yB_CBN9gTNWdWa1wWmpRq2Jg/appointments', 1933, u'7 Vernon Close, Poynton, Stockport, Cheshire, SK12 1NG', u'Peter HORROCKS', 1, u'Total number of appointments 1 - Born June 1933') (u'/officers/EwCC6Fi5_iddiJgpv6xu1xktsyU/appointments', 1940, u'21 Newchurch Lane, Culcheth, Warrington, Cheshire, WA3 5RW', u'Peter HORROCKS', 1, u'Total number of appointments 1 - Born July 1940') (u'/officers/zy7AqPutNxkLwgcJWi45wiJ1RPA/appointments', None, u'Fell View Cottage, Garrs End Lane Grassington, Skipton, BD23 5BB', u'Peter HORROCKS', 1, u'Total number of appointments 1')
for r in c.execute("select * from directors where addr LIKE '%Manchester%' order by cnt desc"):
print(r)
(u'/officers/LnKbanK0iJ7Ovo2SOdySBgL8PVM/appointments', 1942, u'Mon Reve, Manchester Road, Blackrod, Bolton, Lancashire, BL6 5LS', u'Peter HORROCKS', 2, u'Total number of appointments 2 - Born January 1942')
from datetime import date
def dirCompanies(a):
if not len(a['items']): return
print('{}, {}, has the following appointments:'.format(a['name'],
date.today().year-a['date_of_birth']['year'] -(date.today().month <a['date_of_birth']['month'] )))
for aa in a['items']:
print('\t- {}, {} ({}): {} ({})'.format(aa['appointed_to']['company_name'],
aa['address']['locality'],
aa['appointed_to']['company_number'],
aa['officer_role'],
aa['appointed_on'] if 'appointed_on' in aa else aa['appointed_before']))
import re
regexp=re.compile(r'.*companies ?(?:is|are) (.*) a director of?')
m=re.match(regexp,'What companies is Peter Horrocks a director of?')
for c in ch_searchOfficers(m.group(1),n=5)['items']:
dirCompanies(ch_getAppointments(c['links']['self']))
Andrew Peter HORROCKS, 45, has the following appointments: - ANDREW HORROCKS LIMITED, Preston, (04841743): director (2003-07-22) Peter HORROCKS, 74, has the following appointments: - C.HORROCKS & SONS LIMITED, Bolton (00783568): director (1991-06-20) - C.HORROCKS & SONS LIMITED, Lancs (00783568): secretary (1991-06-20) Peter HORROCKS, 56, has the following appointments: - OPEN UNIVERSITY WORLDWIDE LIMITED, Buckinghamshire (01260275): director (2015-06-11) - FUTURELEARN LIMITED, Milton Keynes (08324083): director (2015-06-11) Peter HORROCKS, 70, has the following appointments: - HORROCKS AND CROSS LIMITED, Ulverston (02094977): director (1991-12-31) - HORROCKS AND CROSS LIMITED, Ulverston (02094977): secretary (1991-12-31) Peter HORROCKS, 62, has the following appointments: - P H SOCIAL WORK LIMITED, Sudbury (07477208): director (2010-12-24) - P H CONSULTANCY LIMITED, Sudbury (06936656): secretary (2009-06-17) - P H CONSULTANCY LIMITED, Sudbury (06936656): director (2009-06-17)
regexp=re.compile(r'Which (.*) is a director of (.*?)\??$')
m=re.match(regexp,'Which Peter Horrocks is a director of Futurelearn?')
for c in ch_searchOfficers(m.group(1),n=5,company=m.group(2))['items']:
dirCompanies(ch_getAppointments(c['links']['self']))
Peter HORROCKS, 56, has the following appointments: - OPEN UNIVERSITY WORLDWIDE LIMITED, Buckinghamshire (01260275): director (2015-06-11) - FUTURELEARN LIMITED, Milton Keynes (08324083): director (2015-06-11)
regexp=re.compile(r'.*companies in (.*?) (?:is|are) (.*) a director of\?')
m=re.match(regexp,'What companies in Bolton is Peter Horrocks a director of?')
for c in ch_searchOfficers(m.group(2),n=5)['items']:
dirCompanies(ch_getAppointments(c['links']['self'],location=m.group(1)))
Peter HORROCKS, 74, has the following appointments: - C.HORROCKS & SONS LIMITED, Bolton (00783568): director (1991-06-20)
regexp=re.compile(r'Who were the previous directors of (.*?)[\?]?$')
m=re.match(regexp,'Who were the previous directors of Futurelearn?')
for c in ch_searchCompanies(m.group(1),5,typ='contains')['items']:
print(c['title'])
for o in ch_getCompanyOfficers(c['company_number'],typ='previous')['items']:
print('{} (resigned on {})'.format(o['name'],o['resigned_on']))
print('----')
FUTURELEARN LIMITED BEAN, Martin George (resigned on 2016-03-04) CRAMER, Stephen John (resigned on 2013-01-21) WOODBURN, Alexander Fraser (resigned on 2015-12-18) ----
{u'items': [{u'address': {u'address_line_1': u'CHAMBERS BUILDING', u'address_line_2': u'WALTON HALL', u'locality': u'MILTON KEYNES', u'po_box': u'77', u'postal_code': u'MK7 6BT'}, u'company_number': u'08324083', u'company_status': u'active', u'company_type': u'ltd', u'date_of_creation': u'2012-12-10', u'description': u'08324083 - Incorporated on 10 December 2012', u'description_identifier': [u'incorporated-on'], u'kind': u'searchresults#company', u'links': {u'self': u'/company/08324083'}, u'matches': {u'title': [1, 11]}, u'snippet': u'PO Box 77, Chambers Building, Walton Hall, Milton Keynes, MK7 6BT', u'title': u'FUTURELEARN LIMITED'}], u'items_per_page': 5, u'kind': u'search#companies', u'page_number': 1, u'start_index': 0, u'total_results': 9}
def exact_match(items, txt):
''' Prioritise the list so that exact matches are first... '''
pass