Parsing a nested array on a Google Places JSON result using python
up vote
0
down vote
favorite
Working with python-google-places library, I have obtained the whole set of elements, i.e. place.name, place.place_id, etc.
googpla = GooglePlaces(apikey)
searchtxtplace = googpla.text_search(query = hotel[0]+" "+hotel[1])
for place in searchtxtplace.places:
place.get_details()
listatemp.append(place.name)#.encode('utf-8'))
#print place.name
listatemp.append(place.place_id)
diccionario = place.details
However, problems arise when I try to work with .details. .details is a string with the inner format of a dictionary, something like this (Note: I'm not copying literally all the repeated elements, in order to offer a manageable source for expressing my problem):
{
'vicinity': '17, Calle Victoria, Marjaliza',
'utc_offset': 60,
'rating': Decimal('4.3'),
'photos': [
{
'height': 640,
'html_attributions': [
'<a href="https://maps.google.com/maps/contrib/108485266188009851715/photos">Restaurante El Rincón De La Almazara</a>'
],
'photo_reference': 'CmRaAAAAxqW5EpWB86FNCay2mEZMC_Mv7gf1JIqDWJlQ6dln0okwPrnLicyp35p3S7jzafbGaSK5aAnh_yr2cgq1kmf6m6DPsGDQQm8jmGG5xDqBtoeJck7NQzZG8bZ0aMvGc5mEEhDINxTBkJ7HdEJH3bKY7vuVGhR9NbBR_vHgEL8H7OjXDnDecTWc6w',
'width': 640
}, #[...]
],
'address_components': [
{
'short_name': 'Calle Victoria',
'types': [
'route'
],
'long_name': 'Calle Victoria'
}, #[...]
'reviews': [
{
'profile_photo_url': 'https://lh4.googleusercontent.com/-FAGiynVp-QM/AAAAAAAAAAI/AAAAAAAABpU/GsFl3D2MR80/s128-c0x00000000-cc-rp-mo/photo.jpg',
'author_url': 'https://www.google.com/maps/contrib/103775273852380328675/reviews',
'author_name': 'Luis Alfonso GO',
'rating': 5,
'time': 1541463254,
'relative_time_description': 'in the last week',
'text': 'Buena comida y mejor atención',
'language': 'es'
},
{
'profile_photo_url': 'https://lh6.googleusercontent.com/-OMlBRtCyvwU/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbDV0BzvHwUu5lx1Z6u5-cp1i7bPlw/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg',
'author_url': 'https://www.google.com/maps/contrib/115856190466605639253/reviews',
'author_name': 'Felix Anton PL',
'rating': 5,
'time': 1531241133,
'relative_time_description': '4 months ago',
'text': 'Situado en un pequeño pueblo de Toledo,a 6 Km de Los Yebenes,donde podrá degustar su excelente cocina,con gran variedad de exquisitos entrantes,buenos pescados y unas carnes muy bien presentadas y excelente sabor.nDispone de habitaciones donde poder disfrutar del amanecer de los montes de Toledo.',
'language': 'es'
}, #[...]
]
'types': [
'restaurant',
'point_of_interest',
'food',
'establishment'
],
'place_id': 'ChIJXcd_0BQ9ag0R9TC6IVYxSuI',
'website': 'https://www.facebook.com/rinconde.laalmazara',
'scope': 'GOOGLE'
}
Inside place.details I can work with unique elements, such as 'rating'
listatemp.append(json.dumps(diccionario.get("rating"), default=decimal_default))
But I haven't been able to access to elements inside 'reviews' nested array. Indeed, I would like to loop inside it in order to obtain the five values of 'time'. I have tried to access dumping 'reviews', but I obtain a string instead of a proper json, and I cannot refer to elements such as 'time'
reviewes = (json.dumps(diccionario.get("reviews")))
My question is: How could I access to the inside of 'reviews' nested array or other data structure such as this?
Thank you very much in advance
python json multidimensional-array google-places
add a comment |
up vote
0
down vote
favorite
Working with python-google-places library, I have obtained the whole set of elements, i.e. place.name, place.place_id, etc.
googpla = GooglePlaces(apikey)
searchtxtplace = googpla.text_search(query = hotel[0]+" "+hotel[1])
for place in searchtxtplace.places:
place.get_details()
listatemp.append(place.name)#.encode('utf-8'))
#print place.name
listatemp.append(place.place_id)
diccionario = place.details
However, problems arise when I try to work with .details. .details is a string with the inner format of a dictionary, something like this (Note: I'm not copying literally all the repeated elements, in order to offer a manageable source for expressing my problem):
{
'vicinity': '17, Calle Victoria, Marjaliza',
'utc_offset': 60,
'rating': Decimal('4.3'),
'photos': [
{
'height': 640,
'html_attributions': [
'<a href="https://maps.google.com/maps/contrib/108485266188009851715/photos">Restaurante El Rincón De La Almazara</a>'
],
'photo_reference': 'CmRaAAAAxqW5EpWB86FNCay2mEZMC_Mv7gf1JIqDWJlQ6dln0okwPrnLicyp35p3S7jzafbGaSK5aAnh_yr2cgq1kmf6m6DPsGDQQm8jmGG5xDqBtoeJck7NQzZG8bZ0aMvGc5mEEhDINxTBkJ7HdEJH3bKY7vuVGhR9NbBR_vHgEL8H7OjXDnDecTWc6w',
'width': 640
}, #[...]
],
'address_components': [
{
'short_name': 'Calle Victoria',
'types': [
'route'
],
'long_name': 'Calle Victoria'
}, #[...]
'reviews': [
{
'profile_photo_url': 'https://lh4.googleusercontent.com/-FAGiynVp-QM/AAAAAAAAAAI/AAAAAAAABpU/GsFl3D2MR80/s128-c0x00000000-cc-rp-mo/photo.jpg',
'author_url': 'https://www.google.com/maps/contrib/103775273852380328675/reviews',
'author_name': 'Luis Alfonso GO',
'rating': 5,
'time': 1541463254,
'relative_time_description': 'in the last week',
'text': 'Buena comida y mejor atención',
'language': 'es'
},
{
'profile_photo_url': 'https://lh6.googleusercontent.com/-OMlBRtCyvwU/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbDV0BzvHwUu5lx1Z6u5-cp1i7bPlw/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg',
'author_url': 'https://www.google.com/maps/contrib/115856190466605639253/reviews',
'author_name': 'Felix Anton PL',
'rating': 5,
'time': 1531241133,
'relative_time_description': '4 months ago',
'text': 'Situado en un pequeño pueblo de Toledo,a 6 Km de Los Yebenes,donde podrá degustar su excelente cocina,con gran variedad de exquisitos entrantes,buenos pescados y unas carnes muy bien presentadas y excelente sabor.nDispone de habitaciones donde poder disfrutar del amanecer de los montes de Toledo.',
'language': 'es'
}, #[...]
]
'types': [
'restaurant',
'point_of_interest',
'food',
'establishment'
],
'place_id': 'ChIJXcd_0BQ9ag0R9TC6IVYxSuI',
'website': 'https://www.facebook.com/rinconde.laalmazara',
'scope': 'GOOGLE'
}
Inside place.details I can work with unique elements, such as 'rating'
listatemp.append(json.dumps(diccionario.get("rating"), default=decimal_default))
But I haven't been able to access to elements inside 'reviews' nested array. Indeed, I would like to loop inside it in order to obtain the five values of 'time'. I have tried to access dumping 'reviews', but I obtain a string instead of a proper json, and I cannot refer to elements such as 'time'
reviewes = (json.dumps(diccionario.get("reviews")))
My question is: How could I access to the inside of 'reviews' nested array or other data structure such as this?
Thank you very much in advance
python json multidimensional-array google-places
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Working with python-google-places library, I have obtained the whole set of elements, i.e. place.name, place.place_id, etc.
googpla = GooglePlaces(apikey)
searchtxtplace = googpla.text_search(query = hotel[0]+" "+hotel[1])
for place in searchtxtplace.places:
place.get_details()
listatemp.append(place.name)#.encode('utf-8'))
#print place.name
listatemp.append(place.place_id)
diccionario = place.details
However, problems arise when I try to work with .details. .details is a string with the inner format of a dictionary, something like this (Note: I'm not copying literally all the repeated elements, in order to offer a manageable source for expressing my problem):
{
'vicinity': '17, Calle Victoria, Marjaliza',
'utc_offset': 60,
'rating': Decimal('4.3'),
'photos': [
{
'height': 640,
'html_attributions': [
'<a href="https://maps.google.com/maps/contrib/108485266188009851715/photos">Restaurante El Rincón De La Almazara</a>'
],
'photo_reference': 'CmRaAAAAxqW5EpWB86FNCay2mEZMC_Mv7gf1JIqDWJlQ6dln0okwPrnLicyp35p3S7jzafbGaSK5aAnh_yr2cgq1kmf6m6DPsGDQQm8jmGG5xDqBtoeJck7NQzZG8bZ0aMvGc5mEEhDINxTBkJ7HdEJH3bKY7vuVGhR9NbBR_vHgEL8H7OjXDnDecTWc6w',
'width': 640
}, #[...]
],
'address_components': [
{
'short_name': 'Calle Victoria',
'types': [
'route'
],
'long_name': 'Calle Victoria'
}, #[...]
'reviews': [
{
'profile_photo_url': 'https://lh4.googleusercontent.com/-FAGiynVp-QM/AAAAAAAAAAI/AAAAAAAABpU/GsFl3D2MR80/s128-c0x00000000-cc-rp-mo/photo.jpg',
'author_url': 'https://www.google.com/maps/contrib/103775273852380328675/reviews',
'author_name': 'Luis Alfonso GO',
'rating': 5,
'time': 1541463254,
'relative_time_description': 'in the last week',
'text': 'Buena comida y mejor atención',
'language': 'es'
},
{
'profile_photo_url': 'https://lh6.googleusercontent.com/-OMlBRtCyvwU/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbDV0BzvHwUu5lx1Z6u5-cp1i7bPlw/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg',
'author_url': 'https://www.google.com/maps/contrib/115856190466605639253/reviews',
'author_name': 'Felix Anton PL',
'rating': 5,
'time': 1531241133,
'relative_time_description': '4 months ago',
'text': 'Situado en un pequeño pueblo de Toledo,a 6 Km de Los Yebenes,donde podrá degustar su excelente cocina,con gran variedad de exquisitos entrantes,buenos pescados y unas carnes muy bien presentadas y excelente sabor.nDispone de habitaciones donde poder disfrutar del amanecer de los montes de Toledo.',
'language': 'es'
}, #[...]
]
'types': [
'restaurant',
'point_of_interest',
'food',
'establishment'
],
'place_id': 'ChIJXcd_0BQ9ag0R9TC6IVYxSuI',
'website': 'https://www.facebook.com/rinconde.laalmazara',
'scope': 'GOOGLE'
}
Inside place.details I can work with unique elements, such as 'rating'
listatemp.append(json.dumps(diccionario.get("rating"), default=decimal_default))
But I haven't been able to access to elements inside 'reviews' nested array. Indeed, I would like to loop inside it in order to obtain the five values of 'time'. I have tried to access dumping 'reviews', but I obtain a string instead of a proper json, and I cannot refer to elements such as 'time'
reviewes = (json.dumps(diccionario.get("reviews")))
My question is: How could I access to the inside of 'reviews' nested array or other data structure such as this?
Thank you very much in advance
python json multidimensional-array google-places
Working with python-google-places library, I have obtained the whole set of elements, i.e. place.name, place.place_id, etc.
googpla = GooglePlaces(apikey)
searchtxtplace = googpla.text_search(query = hotel[0]+" "+hotel[1])
for place in searchtxtplace.places:
place.get_details()
listatemp.append(place.name)#.encode('utf-8'))
#print place.name
listatemp.append(place.place_id)
diccionario = place.details
However, problems arise when I try to work with .details. .details is a string with the inner format of a dictionary, something like this (Note: I'm not copying literally all the repeated elements, in order to offer a manageable source for expressing my problem):
{
'vicinity': '17, Calle Victoria, Marjaliza',
'utc_offset': 60,
'rating': Decimal('4.3'),
'photos': [
{
'height': 640,
'html_attributions': [
'<a href="https://maps.google.com/maps/contrib/108485266188009851715/photos">Restaurante El Rincón De La Almazara</a>'
],
'photo_reference': 'CmRaAAAAxqW5EpWB86FNCay2mEZMC_Mv7gf1JIqDWJlQ6dln0okwPrnLicyp35p3S7jzafbGaSK5aAnh_yr2cgq1kmf6m6DPsGDQQm8jmGG5xDqBtoeJck7NQzZG8bZ0aMvGc5mEEhDINxTBkJ7HdEJH3bKY7vuVGhR9NbBR_vHgEL8H7OjXDnDecTWc6w',
'width': 640
}, #[...]
],
'address_components': [
{
'short_name': 'Calle Victoria',
'types': [
'route'
],
'long_name': 'Calle Victoria'
}, #[...]
'reviews': [
{
'profile_photo_url': 'https://lh4.googleusercontent.com/-FAGiynVp-QM/AAAAAAAAAAI/AAAAAAAABpU/GsFl3D2MR80/s128-c0x00000000-cc-rp-mo/photo.jpg',
'author_url': 'https://www.google.com/maps/contrib/103775273852380328675/reviews',
'author_name': 'Luis Alfonso GO',
'rating': 5,
'time': 1541463254,
'relative_time_description': 'in the last week',
'text': 'Buena comida y mejor atención',
'language': 'es'
},
{
'profile_photo_url': 'https://lh6.googleusercontent.com/-OMlBRtCyvwU/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbDV0BzvHwUu5lx1Z6u5-cp1i7bPlw/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg',
'author_url': 'https://www.google.com/maps/contrib/115856190466605639253/reviews',
'author_name': 'Felix Anton PL',
'rating': 5,
'time': 1531241133,
'relative_time_description': '4 months ago',
'text': 'Situado en un pequeño pueblo de Toledo,a 6 Km de Los Yebenes,donde podrá degustar su excelente cocina,con gran variedad de exquisitos entrantes,buenos pescados y unas carnes muy bien presentadas y excelente sabor.nDispone de habitaciones donde poder disfrutar del amanecer de los montes de Toledo.',
'language': 'es'
}, #[...]
]
'types': [
'restaurant',
'point_of_interest',
'food',
'establishment'
],
'place_id': 'ChIJXcd_0BQ9ag0R9TC6IVYxSuI',
'website': 'https://www.facebook.com/rinconde.laalmazara',
'scope': 'GOOGLE'
}
Inside place.details I can work with unique elements, such as 'rating'
listatemp.append(json.dumps(diccionario.get("rating"), default=decimal_default))
But I haven't been able to access to elements inside 'reviews' nested array. Indeed, I would like to loop inside it in order to obtain the five values of 'time'. I have tried to access dumping 'reviews', but I obtain a string instead of a proper json, and I cannot refer to elements such as 'time'
reviewes = (json.dumps(diccionario.get("reviews")))
My question is: How could I access to the inside of 'reviews' nested array or other data structure such as this?
Thank you very much in advance
python json multidimensional-array google-places
python json multidimensional-array google-places
asked Nov 11 at 14:13
Juan Luis Chulilla
418
418
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53249581%2fparsing-a-nested-array-on-a-google-places-json-result-using-python%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