AlienVault-OTX / OTX-Python-SDK

The Python SDK for AlienVault OTX
Other
358 stars 162 forks source link

Sorting of response #65

Open WildDogOne opened 2 years ago

WildDogOne commented 2 years ago

Hello Everyone,

I've noticed that the default sorting of the API responses are ascending. This of course makes searching for recent Pulses a pain, I would have to pull huge amounts of data and sort locally, which is an unnecessary strain on the API Would anyone be interested in adding a parameter to sort descending?

Regards,

Linus

rustybrooks commented 2 years ago

Sorting would probably be nice. But something you might find useful is that there is a (newish) class in the SDK called OTXv2Cached. It's roughly identical to OTXv2 but cached results locally. Whenever you run the functions on it, they update your local cache and then operate on the cached data.

There are 2 things you'll want to do:

o = OTXv2Cached(API_KEY)
o.upate()
for p in o.getall():
   ... etc
rustybrooks commented 2 years ago

Note that the first time you ever run o.update() it'll take a while to populate everything. Also, if you ever suspect the cache is wrong or corrupted, you can just delete the whole cache directory and the next time you run .update() it'll re-populate it.

WildDogOne commented 2 years ago

that is indeed a nice function, but would still make me download heaps of requests, and I honestly don't want to load the OTX API like that. I will sleep over this and if I have too much time I'll try and commit a fix to this