Using postcodes.io API on Django
I'm trying to achieve this:
Use postcodes.io to get the latitude and longitude for each postcode
and render them next to each store location in the template
I have a series of postcodes into a json file:
[
{
"name": "St_Albans",
"postcode": "AL1 2RJ"
},
{
"name": "Hatfield",
"postcode": "AL9 5JP"
},
{
"name": "Worthing",
"postcode": "BN14 9GB"
},
{
"name": "Rustington",
"postcode": "BN16 3RT"
},
{
"name": "Eastbourne",
"postcode": "BN23 6QD"
}, ...
And so on...
I need to check on postcodes.io[0] the latitudes and longitudes of these postcodes, and render these coordinates next to the json result.
My question isn't about on how to render them, it's about on how to POST my json postcodes on their website, and get the respective latitudes and longitudes of each one.
I'm doing this on pure python, any ideas?
0.- https://postcodes.io/docs
python json django
add a comment |
I'm trying to achieve this:
Use postcodes.io to get the latitude and longitude for each postcode
and render them next to each store location in the template
I have a series of postcodes into a json file:
[
{
"name": "St_Albans",
"postcode": "AL1 2RJ"
},
{
"name": "Hatfield",
"postcode": "AL9 5JP"
},
{
"name": "Worthing",
"postcode": "BN14 9GB"
},
{
"name": "Rustington",
"postcode": "BN16 3RT"
},
{
"name": "Eastbourne",
"postcode": "BN23 6QD"
}, ...
And so on...
I need to check on postcodes.io[0] the latitudes and longitudes of these postcodes, and render these coordinates next to the json result.
My question isn't about on how to render them, it's about on how to POST my json postcodes on their website, and get the respective latitudes and longitudes of each one.
I'm doing this on pure python, any ideas?
0.- https://postcodes.io/docs
python json django
1
This isn't really about Django then... what you need to do is make POST requests to the site with your postcode? Have a look at therequestswhich'll make it easy to do a POST request to the end point they specify and retrieve the data. If you need to stick to just the python stdlib, you'll need to look aturllib.requeststuff.
– Jon Clements♦
Nov 25 '18 at 23:15
add a comment |
I'm trying to achieve this:
Use postcodes.io to get the latitude and longitude for each postcode
and render them next to each store location in the template
I have a series of postcodes into a json file:
[
{
"name": "St_Albans",
"postcode": "AL1 2RJ"
},
{
"name": "Hatfield",
"postcode": "AL9 5JP"
},
{
"name": "Worthing",
"postcode": "BN14 9GB"
},
{
"name": "Rustington",
"postcode": "BN16 3RT"
},
{
"name": "Eastbourne",
"postcode": "BN23 6QD"
}, ...
And so on...
I need to check on postcodes.io[0] the latitudes and longitudes of these postcodes, and render these coordinates next to the json result.
My question isn't about on how to render them, it's about on how to POST my json postcodes on their website, and get the respective latitudes and longitudes of each one.
I'm doing this on pure python, any ideas?
0.- https://postcodes.io/docs
python json django
I'm trying to achieve this:
Use postcodes.io to get the latitude and longitude for each postcode
and render them next to each store location in the template
I have a series of postcodes into a json file:
[
{
"name": "St_Albans",
"postcode": "AL1 2RJ"
},
{
"name": "Hatfield",
"postcode": "AL9 5JP"
},
{
"name": "Worthing",
"postcode": "BN14 9GB"
},
{
"name": "Rustington",
"postcode": "BN16 3RT"
},
{
"name": "Eastbourne",
"postcode": "BN23 6QD"
}, ...
And so on...
I need to check on postcodes.io[0] the latitudes and longitudes of these postcodes, and render these coordinates next to the json result.
My question isn't about on how to render them, it's about on how to POST my json postcodes on their website, and get the respective latitudes and longitudes of each one.
I'm doing this on pure python, any ideas?
0.- https://postcodes.io/docs
python json django
python json django
asked Nov 25 '18 at 23:12
NeoVeNeoVe
2,01462774
2,01462774
1
This isn't really about Django then... what you need to do is make POST requests to the site with your postcode? Have a look at therequestswhich'll make it easy to do a POST request to the end point they specify and retrieve the data. If you need to stick to just the python stdlib, you'll need to look aturllib.requeststuff.
– Jon Clements♦
Nov 25 '18 at 23:15
add a comment |
1
This isn't really about Django then... what you need to do is make POST requests to the site with your postcode? Have a look at therequestswhich'll make it easy to do a POST request to the end point they specify and retrieve the data. If you need to stick to just the python stdlib, you'll need to look aturllib.requeststuff.
– Jon Clements♦
Nov 25 '18 at 23:15
1
1
This isn't really about Django then... what you need to do is make POST requests to the site with your postcode? Have a look at the
requests which'll make it easy to do a POST request to the end point they specify and retrieve the data. If you need to stick to just the python stdlib, you'll need to look at urllib.request stuff.– Jon Clements♦
Nov 25 '18 at 23:15
This isn't really about Django then... what you need to do is make POST requests to the site with your postcode? Have a look at the
requests which'll make it easy to do a POST request to the end point they specify and retrieve the data. If you need to stick to just the python stdlib, you'll need to look at urllib.request stuff.– Jon Clements♦
Nov 25 '18 at 23:15
add a comment |
1 Answer
1
active
oldest
votes
You can try with requests. Try like this:
resp = requests.get('https://api.postcodes.io/postcodes/BN14 9GB')
resp.json()
Or
data = {
"postcodes" : ["PR3 0SG", "M45 6GN", "EX165BL"]
}
resp = requests.post('https://api.postcodes.io/postcodes/', data=data)
resp.json()
Integrate these with your json file:
json_data = open('path_to/postcodes.json').read()
for i in json_data:
post_code = i.get('postcode')
resp = requests.get('https://api.postcodes.io/postcodes/{}'.format(postcode))
i.update({'latitude': resp.json().get('latitude'), 'longitude': resp.json().get('longitude')})
print(json_data)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472954%2fusing-postcodes-io-api-on-django%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try with requests. Try like this:
resp = requests.get('https://api.postcodes.io/postcodes/BN14 9GB')
resp.json()
Or
data = {
"postcodes" : ["PR3 0SG", "M45 6GN", "EX165BL"]
}
resp = requests.post('https://api.postcodes.io/postcodes/', data=data)
resp.json()
Integrate these with your json file:
json_data = open('path_to/postcodes.json').read()
for i in json_data:
post_code = i.get('postcode')
resp = requests.get('https://api.postcodes.io/postcodes/{}'.format(postcode))
i.update({'latitude': resp.json().get('latitude'), 'longitude': resp.json().get('longitude')})
print(json_data)
add a comment |
You can try with requests. Try like this:
resp = requests.get('https://api.postcodes.io/postcodes/BN14 9GB')
resp.json()
Or
data = {
"postcodes" : ["PR3 0SG", "M45 6GN", "EX165BL"]
}
resp = requests.post('https://api.postcodes.io/postcodes/', data=data)
resp.json()
Integrate these with your json file:
json_data = open('path_to/postcodes.json').read()
for i in json_data:
post_code = i.get('postcode')
resp = requests.get('https://api.postcodes.io/postcodes/{}'.format(postcode))
i.update({'latitude': resp.json().get('latitude'), 'longitude': resp.json().get('longitude')})
print(json_data)
add a comment |
You can try with requests. Try like this:
resp = requests.get('https://api.postcodes.io/postcodes/BN14 9GB')
resp.json()
Or
data = {
"postcodes" : ["PR3 0SG", "M45 6GN", "EX165BL"]
}
resp = requests.post('https://api.postcodes.io/postcodes/', data=data)
resp.json()
Integrate these with your json file:
json_data = open('path_to/postcodes.json').read()
for i in json_data:
post_code = i.get('postcode')
resp = requests.get('https://api.postcodes.io/postcodes/{}'.format(postcode))
i.update({'latitude': resp.json().get('latitude'), 'longitude': resp.json().get('longitude')})
print(json_data)
You can try with requests. Try like this:
resp = requests.get('https://api.postcodes.io/postcodes/BN14 9GB')
resp.json()
Or
data = {
"postcodes" : ["PR3 0SG", "M45 6GN", "EX165BL"]
}
resp = requests.post('https://api.postcodes.io/postcodes/', data=data)
resp.json()
Integrate these with your json file:
json_data = open('path_to/postcodes.json').read()
for i in json_data:
post_code = i.get('postcode')
resp = requests.get('https://api.postcodes.io/postcodes/{}'.format(postcode))
i.update({'latitude': resp.json().get('latitude'), 'longitude': resp.json().get('longitude')})
print(json_data)
edited Nov 25 '18 at 23:29
answered Nov 25 '18 at 23:18
ruddraruddra
13.8k32748
13.8k32748
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472954%2fusing-postcodes-io-api-on-django%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This isn't really about Django then... what you need to do is make POST requests to the site with your postcode? Have a look at the
requestswhich'll make it easy to do a POST request to the end point they specify and retrieve the data. If you need to stick to just the python stdlib, you'll need to look aturllib.requeststuff.– Jon Clements♦
Nov 25 '18 at 23:15