Skip to content

Instantly share code, notes, and snippets.

@blackfist
Last active December 24, 2015 22:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackfist/6874634 to your computer and use it in GitHub Desktop.
Save blackfist/6874634 to your computer and use it in GitHub Desktop.
Common stuff that I use in VCDB maintenance
import json
import os
from datetime import datetime
import uuid
# i = getIncident('blahblahblah.json')
def getIncident(inString):
return json.loads(open(inString).read())
# updateIncident(i, 'blahblahblah.json', True)
def updateIncident(i,inFilename,validated=False):
i['plus']['modified'] = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
if validated:
i['plus']['analysis_status'] = "Validated"
outfile = open(inFilename,'w')
outfile.write(json.dumps(i,sort_keys=True, indent=2,separators=(',', ': ')))
outfile.close()
# putIncident(i, 'blackfist')
def putIncident(i, analyst="blackfist"):
i['plus']['analyst'] = analyst
i['plus']['created'] = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
identity = str(uuid.uuid4()).upper()
i['incident_id'] = identity
i['plus']['master_id'] = identity
i['source'] = 'vcdb'
outfile = open(identity + '.json','w')
outfile.write(json.dumps(i,sort_keys=True, indent=2,separators=(',', ': ')))
outfile.close()
# show(i['some.variable'])
def show(inDict):
print json.dumps(inDict,sort_keys=True,indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment