Well first of all happy new year to all! … Today marks the start of a new journey for me, I quit my last job in September last year, I needed a change something new, over the last three months I’ve been gathering all the tools to upcycle old objects, make old new again etc. I’ll hopefully get chance to start incorporating bigger projects in the vblog and you lot will see my mini workshop! Still have a lot of work to do, I’ll write another blog when I have some free time. Once again happy new year and have fun hacking!
I’ve been playing with the openweathermap api thought i’d share a little code, the following pulls the json and constructs a string containing the location, temp, tax temp, min temp and humidity. You will need to sign up for an API key and free user account 1st. The free account at the time of writing this allows 50k calls a day so if you’re writing for a small personal project 50k calls should be fine.
Copy the code below to a file
chmod the file if needed …
sudo chmod +x displayweather.py
run the file using …
r = requests.get('http://api.openweathermap.org/data/2.5/forecast/city?id=YOURCITYIDGOESHERE&APPID=YOURAPIKEYGOESHERE')
data = r.json()
mystring = ""
mystring = mystring + data['city']['name'] + " "
mystring = mystring + "Temp:" + str(int(data['list']['main']['temp'] - 273.15)) + "C "
mystring = mystring + "Max:" + str(int(data['list']['main']['temp_max'] - 273.15)) + "C "
mystring = mystring + "Min:" + str(int(data['list']['main']['temp_min'] - 273.15)) + "C "
mystring = mystring + "Hum:" + str(data['list']['main']['humidity']) + "% "