HackerShackOfficial / AI-Smart-Mirror

Smart Mirror with a smart AI 🤖
MIT License
537 stars 214 forks source link

Weather Units #37

Open ghost opened 7 years ago

ghost commented 7 years ago

So somehow, I managed to get this working on my Raspberry pi3 (except the facial recognition).

I've got things running mostly how I want, but I can't figure out for the life of me, how to change the units from Fahrenheit to Celsius for the temperature. Can you please point me in the right direction?

Thanks from the UK, Danny

laststand0810 commented 7 years ago

I think it can be done by writing a small script for conversion from F to C and run it before displaying the result. Weather script have already returned the data in json at the end so just extract it out and modify it in however you like.

C = (F-32)*5/9

ghost commented 7 years ago

Thanks laststand, I was looking at this - https://darksky.net/dev/docs/forecast (scroll to the bottom) i can request the units "SI" which should return the Celsius value, but I can't find where I can change this information. This would seem better than writing a conversion script but if no one knows where to do this, then I may have to.

laststand0810 commented 7 years ago

You can request SI unit by adding to the variable weather_req_url in knowledge.py "units=si" as below

"https://api.darksky.net/forecast/%s/%s,%s?units=si" % (self.weather_api_token, lat, lon)

I haven't test yet but it should do it, you can try and make a request on browser, if it returns, compare with the old requests to see if there's any additional difference that can sabotage the remaining codes, the risk is high that's why I recommend converting the units as earlier, I don't really like tampering others code too much, just keep it easy.

ps: sorry wrong request, missed the '?'

ghost commented 7 years ago

No problem, I'll give it a go and report back - many thanks!