Difference between revisions of "TruxtonLocation"

From truxwiki.com
Jump to navigation Jump to search
Line 51: Line 51:
 
=Sample=
 
=Sample=
  
<syntaxhighlight lang="Python" highlight="47-52">
+
<syntaxhighlight lang="Python" line highlight="41-47">
 
import truxton
 
import truxton
 
import shutil
 
import shutil
Line 64: Line 64:
 
def date_to_filetime(dt):
 
def date_to_filetime(dt):
 
   return EPOCH_AS_FILETIME + (timegm(dt.timetuple()) * HUNDREDS_OF_NANOSECONDS)
 
   return EPOCH_AS_FILETIME + (timegm(dt.timetuple()) * HUNDREDS_OF_NANOSECONDS)
 
def create_event_type(t, id, name):
 
  event_type = t.neweventtype()
 
  event_type.id = id
 
  event_type.name = name
 
  event_type.save()
 
  
 
def add_file(parent_truxton_file, filename):
 
def add_file(parent_truxton_file, filename):
Line 78: Line 72:
 
   source_file.close()
 
   source_file.close()
 
   child.save()
 
   child.save()
 
 
   return child
 
   return child
  
 
def add_media(t):
 
def add_media(t):
 
   media = t.newmedia()
 
   media = t.newmedia()
 +
 
   media.name = "Public Documents"
 
   media.name = "Public Documents"
 
   media.description = "Publicly available documents"
 
   media.description = "Publicly available documents"
Line 95: Line 89:
 
   return media
 
   return media
  
def add_ec(parent_file ):
+
def add_cs(parent_file ):
   child_file = add_file(parent_file, "JW-v-DOJ-reply-02743.pdf")
+
   child_file = add_file(parent_file, "cs.jpg")
  
   artifact = child_file.newartifact()
+
   gps = child_file.newlocation()
   artifact.type = truxton.ENTITY_TYPE_AUTHOR
+
   gps.type = truxton.LOCATION_TYPE_MEETING
   artifact.value = "Bob Smith"
+
   gps.latitude = 51.487329
   artifact.datatype = truxton.DATA_TYPE_ASCII
+
   gps.longitude = -0.124057
   artifact.length = 9
+
   gps.label = "HQ"
   artifact.save()
+
  gps.when= date_to_filetime(datetime.fromisoformat("2016-04-01T12:00:00-05:00"))
 +
   gps.save()
  
 
def main():
 
def main():
Line 113: Line 108:
 
   root_file.save()
 
   root_file.save()
  
   add_ec(root_file)
+
   add_cs(root_file)
  
 
if __name__ == "__main__":
 
if __name__ == "__main__":
 
   main()
 
   main()
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 17:03, 28 May 2020

This class lets you add to the Location table in Truxton.

Attributes and Methods

altitude

fileid

The GUID of the file this location came from. This corresponds to the FileID column of the Location table.

id

This is the GUID of the record. It becomes non-zero after save() has been called. This corresponds to the ID column of the Location table.

label

The short label for this location. This corresponds to the Label column of the Location table.

latitude

The latitude portion of the geographic coordinate using the WGS84 ellipsoid.

longitude

The longitude portion of the geographic coordinate using the WGS84 ellipsoid. Many thanks go to John Harrison for his work.

mediaid

This is the GUID of the media this location came from. This corresponds to the MediaID column of the Location table.

save()

This will commit the information to the Entity table. It will return True if the record was saved to the database, False if there was an error.

tag(tag, reason, origin)

This creates a tag associated with this location in Truxton. The tag parameter is a short, one or two word, bit of text that will be displayed in the UI. The reason a sentence explaining why this location was tagged. The origin is either TAG_ORIGIN_AUTOMATIC (1) or TAG_ORIGIN_HUMAN (2). It will return True if the tag was associated with the location, False on failure.

type

The type of the location. This corresponds to the LocationTypeID column of the Location table. It must be a value listed in the ID column of the LocationType table. You can also use a predefined constant.

when

The time associated with this location in FILETIME ticks.

Sample

 1 import truxton
 2 import shutil
 3 
 4 from datetime import datetime
 5 from calendar import timegm
 6 from pathlib import Path
 7 
 8 EPOCH_AS_FILETIME = 116444736000000000
 9 HUNDREDS_OF_NANOSECONDS = 10000000
10 
11 def date_to_filetime(dt):
12   return EPOCH_AS_FILETIME + (timegm(dt.timetuple()) * HUNDREDS_OF_NANOSECONDS)
13 
14 def add_file(parent_truxton_file, filename):
15   source_file = open(filename, "rb")
16   child = parent_truxton_file.newchild()
17   child.name = Path(filename).name
18   shutil.copyfileobj(source_file, child)
19   source_file.close()
20   child.save()
21   return child
22 
23 def add_media(t):
24   media = t.newmedia()
25 
26   media.name = "Public Documents"
27   media.description = "Publicly available documents"
28   media.case = "DC-SNAFU-2016.2020"
29   media.evidencebag = "EV-0937459386623-a"
30   media.originator = "Jeffrey Jensen"
31   media.latitude = 38.897661
32   media.longitude = -77.036458
33   media.type = truxton.MEDIA_TYPE_LOGICAL_FILES
34   media.save()
35 
36   return media
37 
38 def add_cs(parent_file ):
39   child_file = add_file(parent_file, "cs.jpg")
40 
41   gps = child_file.newlocation()
42   gps.type = truxton.LOCATION_TYPE_MEETING
43   gps.latitude = 51.487329
44   gps.longitude = -0.124057
45   gps.label = "HQ"
46   gps.when= date_to_filetime(datetime.fromisoformat("2016-04-01T12:00:00-05:00"))
47   gps.save()
48 
49 def main():
50   t = truxton.create()
51 
52   media = add_media(t)
53 
54   root_file = media.addroot()
55   root_file.save()
56 
57   add_cs(root_file)
58 
59 if __name__ == "__main__":
60   main()