From 3493b26bd02a32311bf5a91eb15565bff27d2d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 17 Feb 2017 10:32:25 +0100 Subject: [PATCH] Add method to set sightings from a string --- pymisp/api.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index 6e7a7f3..7465138 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -33,9 +33,11 @@ from .mispevent import MISPEvent, MISPAttribute, EncodeUpdate # Least dirty way to support python 2 and 3 try: basestring + unicode warnings.warn("You're using python 2, it is strongly recommended to use python >=3.4") except NameError: basestring = str + unicode = str class distributions(object): @@ -1133,13 +1135,18 @@ class PyMISP(object): response = session.post(url) return self._check_response(response) - def sighting_per_json(self, json_file): + def set_sightings(self, sightings): + if isinstance(sightings, dict): + sightings = json.dumps(sightings) session = self.__prepare_session() + url = urljoin(self.root_url, 'sightings/add/') + response = session.post(url, data=sightings) + return self._check_response(response) + + def sighting_per_json(self, json_file): with open(json_file) as f: jdata = json.load(f) - url = urljoin(self.root_url, 'sightings/add/') - response = session.post(url, data=json.dumps(jdata)) - return self._check_response(response) + return self.set_sightings(jdata) # ############## Sharing Groups ##################