add export-import of a list

pull/1/head
Raphaël Vinot 2014-04-14 19:18:12 +02:00
parent 93ddd4cf50
commit 07b66ad05f
2 changed files with 28 additions and 9 deletions

View File

@ -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:

View File

@ -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')