For python there is a library called jsondiff
that can be useful, along with the library requests
In the following example we downloaded the JSON every 10 minutes, and I applied diff
between what we just downloaded and what we had downloaded in the previous iteration [Note: in free plan , the OpenWeather api updates your data every 2h , so you can increase the sampling time without problems, because this example would not produce results until have executed about 12 times the loop).
import time
import requests
from jsondiff import diff
api_url = 'http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22'
data = requests.get(api_url).json()
while (True):
time.sleep(10*60)
newdata = requests.get(api_url).json()
diferencia = diff(newdata, data)
if diferencia:
print(diferencia)
data = newdata
In this example I limit myself to save the result of the diff (which will be an empty dictionary in case there have been no changes), and then print it if there were changes. But you can do anything else from that result. Look at the documentation of jsondiff
to see what structure the json has that returns diff
when there were changes.