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?
Asked
Active
Viewed 1,435 times
1 Answers
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
-
So I did what that said to do, and it told me that now the url is undefined. – AwesomeUser Apr 24 '14 at 20:55
-
Can you post the modified code? It's likely just an issue of scoping the url variable to the new function being executed by the timer. – DeaconDesperado Apr 24 '14 at 20:56