Fix python3 compat. Make Pep8 happy.

pull/21/head
Raphaël Vinot 2016-06-16 13:48:40 +09:00
parent a42be22f78
commit 8241d4ce93
2 changed files with 27 additions and 32 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
*.pyc *.pyc
examples/keys.py examples/keys.py
examples/cudeso.py examples/cudeso.py
examples/feed-generator/output/*.json
build/* build/*
dist/* dist/*
pymisp.egg-info/* pymisp.egg-info/*

View File

@ -1,29 +1,24 @@
#!/usr/bin/python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys
import json import json
import os import os
from pymisp import PyMISP from pymisp import PyMISP
from settings import * from settings import url, key, ssl, outputdir, filters, valid_attribute_distribution_levels
objectsToSave = { objectsToSave = {'Orgc': {'fields': ['name', 'uuid'],
'Orgc': { 'multiple': False,
'fields': ['name', 'uuid'], },
'multiple': False, 'Tag': {'fields': ['name', 'colour', 'exportable'],
}, 'multiple': True,
'Tag': { },
'fields': ['name', 'colour', 'exportable'], 'Attribute': {'fields': ['uuid', 'value', 'category', 'type',
'multiple': True, 'comment', 'data', 'timestamp', 'to_ids'],
}, 'multiple': True,
'Attribute': { },
'fields': ['uuid', 'value', 'category', 'type', }
'comment', 'data', 'timestamp',
'to_ids'],
'multiple': True,
},
}
fieldsToSave = ['uuid', 'info', 'threat_level_id', 'analysis', fieldsToSave = ['uuid', 'info', 'threat_level_id', 'analysis',
'timestamp', 'publish_timestamp', 'published', 'timestamp', 'publish_timestamp', 'published',
@ -43,15 +38,15 @@ def init():
def saveEvent(misp, uuid): def saveEvent(misp, uuid):
try: event = misp.get_event(uuid)
event = misp.get_event(uuid) if not event.json().get('Event'):
event = __cleanUpEvent(event) print('Error while fetching event: {}'.format(event.json()['message']))
event = json.dumps(event)
eventFile = open(os.path.join(outputdir, uuid + '.json'), 'w')
eventFile.write(event)
eventFile.close()
except:
sys.exit('Could not create file for event ' + uuid + '.') sys.exit('Could not create file for event ' + uuid + '.')
event = __cleanUpEvent(event)
event = json.dumps(event)
eventFile = open(os.path.join(outputdir, uuid + '.json'), 'w')
eventFile.write(event)
eventFile.close()
def __cleanUpEvent(event): def __cleanUpEvent(event):
@ -103,7 +98,8 @@ def saveManifest(manifest):
manifestFile = open(os.path.join(outputdir, 'manifest.json'), 'w') manifestFile = open(os.path.join(outputdir, 'manifest.json'), 'w')
manifestFile.write(json.dumps(manifest)) manifestFile.write(json.dumps(manifest))
manifestFile.close() manifestFile.close()
except: except Exception as e:
print(e)
sys.exit('Could not create the manifest file.') sys.exit('Could not create the manifest file.')
@ -112,8 +108,7 @@ def __addEventToManifest(event):
for eventTag in event['EventTag']: for eventTag in event['EventTag']:
tags.append({'name': eventTag['Tag']['name'], tags.append({'name': eventTag['Tag']['name'],
'colour': eventTag['Tag']['colour']}) 'colour': eventTag['Tag']['colour']})
return { return {'Orgc': event['Orgc'],
'Orgc': event['Orgc'],
'Tag': tags, 'Tag': tags,
'info': event['info'], 'info': event['info'],
'date': event['date'], 'date': event['date'],
@ -138,8 +133,7 @@ if __name__ == '__main__':
for event in events: for event in events:
saveEvent(misp, event['uuid']) saveEvent(misp, event['uuid'])
manifest[event['uuid']] = __addEventToManifest(event) manifest[event['uuid']] = __addEventToManifest(event)
print "Event " + str(counter) + "/" + str(total) + " exported." print("Event " + str(counter) + "/" + str(total) + " exported.")
counter += 1 counter += 1
saveManifest(manifest) saveManifest(manifest)
print 'Manifest saved. Feed creation completed.' print('Manifest saved. Feed creation completed.')