felixhageloh / weather-widget

A weather widget for Übersicht
64 stars 32 forks source link

Cities with apostrophes in the name don't work. #19

Open nonissue opened 9 years ago

nonissue commented 9 years ago

I'm currently in a Canadian city ("St. John's, Newfoundland") and though my location is detected successfully, I consistently get an error saying "Are you connected to the internet?". I've tested it by setting location to static and putting in other cities with apostrophes in their names, and they also fail. I'd like to add this works where I normally live as well.

nonissue commented 9 years ago

Double escaping apostrophes in the YQL query seems to resolve the location issue, but afterwards, the units function stops working and defaults to F. I'm sure it's to do with the apostrophes but I don't really know enough to debug it. If you just want it to work and have this issue:

Insert on line 91:

city   = city.replace(/'/g, "\\'");

and then if you want celsius, replace the current query with:

"where location='"+city+", "+region+"' and unit='c'";

A total hack, but it works for me.

felixhageloh commented 9 years ago

That's annoying ... I also just tried https://weather.yahoo.com. When you start typing "St. John's" you get the autocomplete suggestion "St. John's, NL, CA" and if you select it, everything works fine. However if you type/paste that exact string and search, it won't find anything. So it sounds like an issue with yahoo weather - great that you found a workaround!

nonissue commented 9 years ago

I think it is maybe a bug with YQL and non-US cities. I played around with their YQL test console and the results were inconsistent. I might have another look at it, though I don't know it matters.