Difference between revisions of "TruxtonChildFileIO newlocation"

From truxwiki.com
Jump to navigation Jump to search
(Created page with "This create new location record from a file in Truxton. It automatically associates the parent file and media identifiers used in the Location table. =Sy...")
 
Line 1: Line 1:
 
This create new location record from a file in Truxton.
 
This create new location record from a file in Truxton.
It automatically associates the parent file and media identifiers used in the [[Location Table | Location table.]]
+
It automatically associates the parent file and media identifiers used in the <code><nowiki>[</nowiki>[[Location Table|Location]]<nowiki>]</nowiki></code> table.
  
 
=Syntax=
 
=Syntax=
<syntaxhighlight lang="Python">
+
<source lang="Python">
 
object newlocation();
 
object newlocation();
</syntaxhighlight>
+
</source>
  
 
=Return value=
 
=Return value=
Line 11: Line 11:
  
 
=Sample=
 
=Sample=
 
+
<source lang="Python" highlight="28">
<syntaxhighlight lang="Python" highlight="28">
 
 
import truxton
 
import truxton
 
import shutil
 
import shutil
Line 55: Line 54:
 
if __name__ == "__main__":
 
if __name__ == "__main__":
 
   main()
 
   main()
 
+
</source>
</syntaxhighlight>
 

Revision as of 12:28, 22 February 2021

This create new location record from a file in Truxton. It automatically associates the parent file and media identifiers used in the [Location] table.

Syntax

object newlocation();

Return value

A Location object

Sample

import truxton
import shutil
from datetime import datetime
from calendar import timegm
from pathlib import Path

EPOCH_AS_FILETIME = 116444736000000000
HUNDREDS_OF_NANOSECONDS = 10000000

def date_to_filetime(dt):
  return EPOCH_AS_FILETIME + (timegm(dt.timetuple()) * HUNDREDS_OF_NANOSECONDS)

def add_file(parent_truxton_file, filename):
  source_file = open(filename, "rb")
  child = parent_truxton_file.newchild()
  child.name = Path(filename).name
  shutil.copyfileobj(source_file, child)
  source_file.close()
  child.save()
  return child

def main():
  t = truxton.create()
  file = t.getfileid("5ec2a123-74d6-5da7-0653-4e6800000000")

  child = add_file(file, "C:/photos/fnulnu.jpg")

  geo = child.newlocation()

  geo.label = "Flynn and Lynde Home"
  geo.when = date_to_filetime(datetime.utcnow())
  geo.latitude = 34.093431
  geo.longitude = -118.393153
  geo.altitude = 100
  geo.type = truxton.LOCATION_TYPE_CACHED_POSITION

  if geo.save() is True:
    print( "New Location saved as id " + geo.id)


if __name__ == "__main__":
  main()