Difference between revisions of "TruxtonEnumeration"

From truxwiki.com
Jump to navigation Jump to search
Line 1: Line 1:
 
This class lets you enumerate things in Truxton.
 
This class lets you enumerate things in Truxton.
 
=Attributes and Methods=
 
=Attributes and Methods=
==<code>addnote(text: str) -> boolean</code>==
 
This adds an investigator's note.
 
The <code>text</code> parameter is the contents of the note.
 
It will return
 
[https://docs.python.org/3.10/library/constants.html?highlight=false#True True] if the tag was associated with the communication, [https://docs.python.org/3.10/library/constants.html?highlight=false#False False] on failure.
 
The note is stored in the <code>[InvestigatorNote]</code> table in the database.
 
 
 
==<code>currentfile: [[TruxtonFileIO]]</code>==
 
==<code>currentfile: [[TruxtonFileIO]]</code>==
 
The [[TruxtonFileIO|file]] that contained whatever is being enumerated.
 
The [[TruxtonFileIO|file]] that contained whatever is being enumerated.
Line 16: Line 9:
 
==<code>currentmedia: [[TruxtonMedia]]</code>==
 
==<code>currentmedia: [[TruxtonMedia]]</code>==
 
The [[TruxtonMedia|media]] that contained whatever is being enumerated.
 
The [[TruxtonMedia|media]] that contained whatever is being enumerated.
 +
 +
==<code>reset() -> None</code>==
 +
Rewinds the enumeration to the beginning.
  
 
==<code>scope: int</code>==
 
==<code>scope: int</code>==
Line 45: Line 41:
 
This sample will enumerate all of the investigations in Truxton and list all media in those investigations.
 
This sample will enumerate all of the investigations in Truxton and list all media in those investigations.
 
The output is [http://en.wikipedia.org/wiki/JSON JSON] format.
 
The output is [http://en.wikipedia.org/wiki/JSON JSON] format.
 +
There is a more complete example on [https://github.com/SammyB428/Truxton-Samples/blob/main/Scripts/Enumerate.py GitHub].
  
 
<source lang="Python" highlight="59-61,63,68,72">
 
<source lang="Python" highlight="59-61,63,68,72">

Revision as of 12:16, 2 June 2023

This class lets you enumerate things in Truxton.

Attributes and Methods

currentfile: TruxtonFileIO

The file that contained whatever is being enumerated.

currentinvestigation: TruxtonInvestigation

The investigation that contained whatever is being enumerated.

currentmedia: TruxtonMedia

The media that contained whatever is being enumerated.

reset() -> None

Rewinds the enumeration to the beginning.

scope: int

This sets the level at which things can be enumerated. The default is a global scope, you want to enumerate everything in Truxton. You can set it to:

  • Type_Investigation - This will tell Truxton you wish to enumerate things in a particular investigation
  • Type_Media - This will tell Truxton you wish to enumerate things in a particular piece of media

scopeid: str | UUID

This isolates the scope to the particular investigation or media you wish to enumerate.

target: int

These are the things you want to enumerate. It can be one of the following:

Sample

This sample will enumerate all of the investigations in Truxton and list all media in those investigations. The output is JSON format. There is a more complete example on GitHub.

import sys
import json
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton

trux = truxton.create()

media_status_names = json.loads(trux.mediastatusnames())
media_type_names = json.loads(trux.mediatypenames())

def output_investigation(investigation: truxton.TruxtonInvestigation, instance: int) -> None:
 if instance > 0:
  print(",")

 d = dict()
 d["id"] = investigation.id.lower()
 d["name"] = investigation.name
 d["case"] = investigation.case
 d["description"] = investigation.description
 d["jurisdiction"] = str(investigation.jurisdiction)
 d["opened"] = F"{investigation.opened:%Y-%m-%dT%H:%M:%SZ}"
 d["status"] = str(investigation.status)
 d["type"] = str(investigation.type)

 object_name = dict()
 object_name["investigation"] = d;
 print(json.dumps(object_name, ensure_ascii = False, sort_keys = True))

def output_media(media: truxton.TruxtonMedia) -> None:
 d = dict()
 d["id"] = media.id.lower()
 d["name"] = media.name
 d["case"] = media.case
 d["loadconfiguration"] = str(media.configid)
 d["created"] = F"{media.created:%Y-%m-%dT%H:%M:%SZ}"
 d["description"] = media.description
 d["evidencebag"] = media.evidencebag
 d["expires"] = F"{media.expires:%Y-%m-%dT%H:%M:%SZ}"
 d["generatedfolderid"] = media.generatedfolderid.lower()
 d["latitude"] = str(media.latitude)
 d["longitude"] = str(media.longitude)
 d["originator"] = media.originator
 d["percentcomplete"] = str(media.percentcomplete)
 d["rootid"] = media.rootid.lower()
 d["status"] = str(media.status)
 d["statusname"] = media_status_names[str(media.status)]
 d["type"] = str(media.type)
 d["typename"] = media_type_names[str(media.type)]
 d["updated"] = F"{media.updated:%Y-%m-%dT%H:%M:%SZ}"

 object_name = dict()
 object_name["media"] = d;
 print("," + json.dumps(object_name, ensure_ascii = False, sort_keys = True))

def dump_investigation(investigation: truxton.TruxtonInvestigation, instance: int) -> None:
 output_investigation(investigation, instance)

 investigation_media = trux.newenumerator()
 investigation_media.scope = truxton.Type_Investigation
 investigation_media.scopeid = investigation.id
 investigation_media.target = truxton.Type_Media

 for media in investigation_media:
  output_media(media)

def main():
 investigations = trux.newenumerator()
 investigations.target = truxton.Type_Investigation

 print("[")
 instance = 0
 for investigation in investigations:
  dump_investigation(investigation, instance)
  instance += 1
 print("]")

if __name__ == "__main__":
 main()