0

I have a python script that pulls information from an API (JSON format) and then executes a series of commands and computations based on the API data. I want the computation to run only when there is new data available. So my question is: what is the best way to detect the availability of new data in the API?

My current idea is to just pull all the data once every day. Hash the entire thing and compare the hash-numbers. The problem is that python doesn't want to hash a dicitionary object. Any suggestions?

  • You can try to take a look at the difference in dictionaries: [How to get the difference between two dictionaries in Python?](https://stackoverflow.com/questions/32815640/how-to-get-the-difference-between-two-dictionaries-in-python) – Thijs van Ede Oct 02 '18 at 12:04

2 Answers2

0

The idea with the hash value also came to me first. Can you create a hash value with hashlib?

import hashlib
import json

...
hashed = hashlib.sha1(json.dumps(your_api_dict, sort_keys=True).encode()).hexdigest()
g3n35i5
  • 485
  • 1
  • 4
  • 14
0

you can convert data to string and then hash the result. you can use json.dumps() to convert