0

I am running this python code on my raspberry pi, which checks USGS data and finds the magnitude of all earthquakes within the last hour. The only problem is that the json is always changing. How do I make it keep checking to see if it changed again?

AwesomeUser
  • 117
  • 13

1 Answers1

0

The simplest setup would be to periodically run the request logic over and over, caching the results each time, perhaps with an optional increasing backoff if several requests yield the same results.

You could then compare the new parsed values with the previous ones if the delta is what you really care about, or just replace inline if you're just want to ensure the freshest. Since json.loads by default deserializes to a dictionary, all the standard dictionary methods are available to make comparisons.

Very simple examples of timed-interval callbacks are available on other SO posts

Alternatively there are heavier solutions like APScheduler, though that's probably a lot more than you'd be interested in for a Raspberry Pi.

Community
  • 1
  • 1
DeaconDesperado
  • 9,977
  • 9
  • 47
  • 77