From 07b66ad05f8a41ff44e223ba06ba6658c98725b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 14 Apr 2014 19:18:12 +0200 Subject: [PATCH] add export-import of a list --- pymisp/api.py | 2 +- pymisp/testing.py | 35 +++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index e7776a5..03747c2 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -99,7 +99,7 @@ class PyMISP(object): """ Search via the Rest API """ - search = self.url + '/events/restSearch/download/{}/{}/{}/{}/{}' + search = self.url + '/restSearch/download/{}/{}/{}/{}/{}' val = self.__prepare_rest_search(values, not_values).replace('/', '|') tag = self.__prepare_rest_search(tags, not_tags).replace(':', ';') if len(val) == 0: diff --git a/pymisp/testing.py b/pymisp/testing.py index 849ab16..c1fc985 100644 --- a/pymisp/testing.py +++ b/pymisp/testing.py @@ -10,22 +10,41 @@ url_dest = 'https://misppriv.circl.lu' source = None destination = None + def init(): global source global destination source = PyMISP(url_source, src, 'xml') destination = PyMISP(url_dest, dest, 'xml') + +def _to_utf8(request): + to_return = None + if 'json' in request.headers['content-type']: + to_return = request.json() + else: + to_return = request.text.encode('utf-8') + return to_return + + def copy_event(event_id): r_src = source.get_event(event_id) - if 'json' in r_src.headers['content-type']: - to_send = r_src.json() - else: - to_send = r_src.text.encode('utf-8') - r_dst = destination.add_event(to_send) - #print r_dst.text + to_send = _to_utf8(r_src) + return destination.add_event(to_send) + + +def export_osint(): + # Warning: does not exports the samples/attachements + osint = source.search(tags='OSINT') + return _to_utf8(osint) + + +def list_copy(filename): + with open(filename, 'r') as f: + for l in f: + l = int(l.strip()) + copy_event(l) if __name__ == '__main__': init() - copy_event(0000) - + list_copy('list')