Closed TheyCallMeTrinity closed 6 years ago
Hey, you're welcome and thanks for the idea! I changed _getcurrent to _getid and added the popularity and other detail information to the response.
Many thanks, I'm glad you liked the idea. However, when I try it, I get back the error "The query string is malformed", though with only 2 params I'm pretty sure I wrote them in the right way :-) Could you please check if there is a leftover issue or it is just me? Thanks.
Ok, I tried again with some other IDs (if you want to reproduce: the first is Louvre Museum, the second is Eiffel Tower and the third is Sacre-Coeur basilica). The first one returns the error above, the second one runs fine but no popular time is returned (though they're present in the google search), while the third one is working exactly as expected. Is this a Google's issue (or even mine)?
Are you using those place id's?
Sacre-Coeur ChIJg8vfy1xu5kcRA1tGDNGsgHA Louvre ChIJD3uTd9hx5kcR1IQvGfr8dbk Eiffel Tower ChIJrbS_8-Fv5kcRzSjPvnUT03s
I don't get errors running this locally
Actually not, mine are different, maybe because I get them via javascript instead of web service. To be precise: Sacre-Coeur 7675909b2af3729b5a18a1649fc7926a51dcf2cc Eiffel 78dcba4698e28ed666a2bf94fe08fabc0bb11ffe Louvre 9a007d81ca8f47ed30ddaf39c4174ef773b351e0
I just tried yours and they work, even though the Eiffel one still does not report any popular time.
UPDATE: I just figured out that there are two IDs: a "id" and a "place_id", I was using the first ones while yours are the second ones. Yet there is the problem with Eiffel.
Ok, I never used the javscript IDs, how did you retrieve them?
It's strange that the Eiffel tower has no current popularity. For me it returned a current popularity, only Louvre not as it's closed.
Could you provide the JSON response for the Eiffel tower?
IDs issue is solved, check post above if you didn't notice the edit ;-) Here is the Eiffel result (using the right ID)
{
"id":"ChIJrbS_8-Fv5kcRzSjPvnUT03s",
"name":"Eiffel Tower",
"address":"Tour Eiffel, 5 Avenue Anatole France, 75007 Paris, France",
"types":[
"premise"
],
"coordinates":{
"lat":48.8583698,
"lng":2.2944833
},
"rating_n":0,
"populartimes":[
] }
I'm not sure what is causing this issue, I get a perfectly fine response (see below). Could you provide more information on your system/python version?
It also seems as if there are some issues with the Eiffel tower, the response for the webservice detail request does for example not contain components specified in https://developers.google.com/places/web-service/details like rating or review.
{
'id': 'ChIJrbS_8-Fv5kcRzSjPvnUT03s',
'name': 'Eiffel Tower',
'address': 'Tour Eiffel, 5 Avenue Anatole France, 75007 Paris, France',
'types': [
'premise'
],
'coordinates': {
'lat': 48.8583698,
'lng': 2.2944833
},
'rating': 4.6,
'rating_n': 34253,
'current_popularity': 42,
'populartimes': [
{
'name': 'Monday',
'data': [
0,
0,
0,
0,
0,
0,
0,
0,
0,
18,
32,
47,
58,
63,
63,
60,
57,
54,
54,
53,
50,
43,
31,
0
]
},
{
'name': 'Tuesday',
'data': [
0,
...
}
Uh, that's weird. Tried again and still same response. System is Win7 and py version is 3.6.3. The script consists in two lines (+imports), one with the function call and one to dump json to a file; i'm running it with "py -3 filename.py" since I also have other Python versions.
I'm not sure where this problem is coming from it worked for me with Window and/or VPN. Maybe try reinstalling the library.
I reinstalled the library but nothing changed. I'll try to put some prints and debug it and will let you know if I find something strange. The only thing I can think of is that the Eiffel id has "_" and "-" characters, while other IDs don't. Might this lead to some unexpected behaviour in sending the request?
No this is just a part of the random string, e.g. ChIJo-2ZufR1nkcRWEZYKjOWbio. Some debug information would be great, thanks!
Yes, I thought it might be that special characthers caused some troubles with e.g. format function. Anyway, it's actually quite hard to figure out where the problem happens. Looking at the output, I can surely say that error occurs before line 326, where "popularity" seems to be None. Figuring out why is indeed much harder, especially because yours works well. Do you have any idea about where to look and put breakpoints? Also, I compared the results of calling the API via web (using "detail_str") with Eiffel and Louvre, and the latter is longer, including more information, but again I can't imagine what should I be looking for.
UPDATE: At line 262 jdata seems to contain populartimes data, while they don't get to line 272. I found out that by doing info = jdata[0][1][0][14]
you get an empty variable, or something like that. So is this an index problem?!
Can you post the the complete contents of jdata? info should contain all of the information except populartimes/current_popularity if its not there
By now I'm unable, I'll post it in the afternoon. Anyway I confirm that the trouble is within the indexes. I saved jsons from jdata for both Louvre and Eiffel. Going to [0][1][0][14] for the first one returns what is expected, the second is empty. I'll try to find the right indexes, but I actually have a possible explanation: might this be a problem of localization? I mean, depending on user language indexes may be different, is that possible?
I noticed that what I have for louvre in jdata[0][1][0][14] is for eiffel in jdata[0][1][1][14]. Maybe a possible solution would be to iterate over jdata[0][1] to find the right next index.
So, I came to a conclusion. Since the problems are only in the third index, you could check if [i][14]
is not null to determine i
. I have very few knowledge in python, but at line 270 I changed the code to
info = jdata[0][1]
for i in range(len(info)):
try:
info=info[i][14]
except IndexError:
continue
This might not be the better solution, but it indeed works! I suppose that a little reworking on the code above should do the trick, handling any possible index variation (at least on the third).
Glad you could fix it! However, I would still like to reproduce the error or find out why there are additional parameters in your JSON response.
Could you provide the complete data from jdata?
Yep, and I think such kind of fix (to search for the right index) should work for any case out there. It's actually quite hard to provide the full jdata, especially to paste it here. However I'm almost sure it depends on the user language: additional data may be displayed depending on user language/setting, thus the variations in the indexes.
What language do you use, so I can maybe reproduce this and then update the code? I tried a few different countries via VPN previously, but none of the replies had the same problem.
Italian. Another weird thing I noticed is that using the javascript places API for Eiffel Tower, some stuff is still missing, e.g. opening hours, rating and so on.
So, sadly I could not reproduce this with changed language settings... No idea what is going on. And yeah, the Eiffel tower response is missing data that should be available.
It also seems as if there are some issues with the Eiffel tower, the response for the webservice detail request does for example not contain components specified in https://developers.google.com/places/web-service/details like rating or review.
I guess this is a strange behavior from Google's side, not sure what caused this. If some other people will report similar issues I would update the code.
Thx for the help trying to figure this out!
That's weird! Surely it's Google's fault, but I can't figure out why. Maybe it could be related to Google account, or API key or something else, but I'm still not sure since I can't remember of any particular setting. I'll try and keep the fix I wrote above (that by now seems to work well and looks like a simple & pretty way to solve the issue) and will let you know if I'll find out anything else. Thanks again!
Hello, first thanks for this amazing feature! It's really, really useful since it sounds like Big G doesn't want to share PopTimes with us via API. I was wondering if it would be possible to add a simplified function to this repo, for cases in which you only need PopTimes for one place and you already have place ID. It could be something like populartimes.IDget(api_key, ID). It would save time by reducing the amount of code to be executed with many benefits. I'm not familiar enough with Python, but I think that it wouldn't be hard to add it, since it should use only a part of what's already there. Thanks again.