{"id":7742,"date":"2023-04-05T07:51:10","date_gmt":"2023-04-05T07:51:10","guid":{"rendered":"https:\/\/davelevy.info\/wiki\/?p=7742"},"modified":"2023-04-06T10:46:32","modified_gmt":"2023-04-06T10:46:32","slug":"political-postcodes","status":"publish","type":"post","link":"https:\/\/davelevy.info\/wiki\/political-postcodes\/","title":{"rendered":"Political postcodes"},"content":{"rendered":"\n<p>How to get an MP name from a post code? I fancy doing this, Obviously \u201cthey work for you\u201d have this? Could I write a script or copy their code? I had a look and on first review their database is obfuscated. Can I build my own and how and where to host it? I would also need a javascript or html interface. Here are my notes \u2026.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">Data<\/h3>\n\n\n\n<p>Where to get the data?&nbsp; See <a href=\"https:\/\/www.dannybrien.com\/mpdata\/\">https:\/\/www.dannybrien.com\/mpdata\/<\/a>&nbsp; and <a href=\"https:\/\/geoportal.statistics.gov.uk\/datasets\/ons-postcode-directory-february-2023-version-2\/about\">https:\/\/geoportal.statistics.gov.uk\/datasets\/ons-postcode-directory-february-2023-version-2\/about<\/a> . The file has too many rows for excel and has been broken up into chunks.<\/p>\n\n\n\n<p>I think we need a database and SQL seems the obvious choice. On inspection of the data, I think the implementation schema looks like this.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2023\/04\/polpostcode-schema.png\"><img loading=\"lazy\" decoding=\"async\" width=\"450\" height=\"73\" src=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2023\/04\/polpostcode-schema.png\" alt=\"\" class=\"wp-image-7743\" srcset=\"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2023\/04\/polpostcode-schema.png 450w, https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2023\/04\/polpostcode-schema-300x49.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><figcaption class=\"wp-element-caption\">Constituency &#8211; Postcode ERM<\/figcaption><\/figure><\/div>\n\n\n<p>The ONS data uses a constituency code as a surrogate key. The database would probably be easier to implement using this as the foreign key, but the solution would be more compact if the name was used as the foreign key. (Does this mean that constituency name needs to be fixed length, I mean I think not.) postcode.constituencyname is the foreign key to constituency table.<\/p>\n\n\n\n<p>An alternative to an SQL database might by a javascript or python daemon.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Which Database?<\/h3>\n\n\n\n<p>I need to choose a database and hosting provider. \u00a0I could host my own at dfl.ddns.net, but, I ran a google <a href=\"https:\/\/www.google.com\/search?q=free+database+service\">query, free database service<\/a> and the answers focused on free software not a free service, but I found, <a href=\"https:\/\/www.hostingadvice.com\/how-to\/best-free-database-hosting\/\">14 best free database hosting\/<\/a> by Laura Bernheim at hostingadvice.com, which while offering some free services reminds me I have the capacity to build the database within my <a href=\"https:\/\/www.ionos.co.uk\/\">ionos<\/a> account. And there&#8217;s this, <a href=\"https:\/\/chipwired.com\/databases-for-raspberry-pi\/\">6 databases for Raspberry Pi<\/a>. and this which <a href=\"https:\/\/raspberrytips.com\/best-database-raspberry-pi\/\">recommends a more traditional five<\/a> i.e. I have heard of all of them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Queries on the net<\/h3>\n\n\n\n<p>Yeah, not sure! The best answer would seem to be <a href=\"https:\/\/www.google.com\/search?q=how+to+present+a+database+query+to+an+html+page+using+javascript\">javascript<\/a>, but there maybe <a href=\"https:\/\/www.google.com\/search?q=how+to+present+a+database+query+to+an+html+page+using+javascript\">other solutions<\/a>, python or PHP, maybe even RDF &amp; SPARQL although that would take a lot of skill that I don&#8217;t currently posses.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to get an MP name from a post code? I fancy doing this, Obviously \u201cthey work for you\u201d have this? Could I write a script or copy their code? I had a look and on first review their database is obfuscated. Can I build my own and how and where to host it? I&#8230;<\/p>\n","protected":false},"author":1,"featured_media":7745,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_share_on_mastodon":"0"},"categories":[140,3],"tags":[141,1914,1035,911,1421,130,849,1861],"class_list":["post-7742","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-politics","category-technology","tag-politics-2","tag-postcode","tag-sql","tag-technology","tag-web-hosting","tag-web-services","tag-webdesign","tag-websites"],"share_on_mastodon":{"url":"","error":""},"jetpack_featured_media_url":"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2023\/04\/web-domain-service-website-development-seo-1571969-pxhere.com_.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/7742","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/comments?post=7742"}],"version-history":[{"count":4,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/7742\/revisions"}],"predecessor-version":[{"id":7758,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/7742\/revisions\/7758"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media\/7745"}],"wp:attachment":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media?parent=7742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/categories?post=7742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/tags?post=7742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}