Difference between revisions of "TruxtonFileIO newexif"

From truxwiki.com
Jump to navigation Jump to search
Line 1: Line 1:
 
This create new [https://en.wikipedia.org/wiki/Exif EXIF] record from a file in Truxton.
 
This create new [https://en.wikipedia.org/wiki/Exif EXIF] record from a file in Truxton.
It automatically associates the parent file and media identifiers used in the [[EXIF Table | EXIF table.]]
+
It automatically associates the parent file and media identifiers used in the <code><nowiki>[</nowiki>[[EXIF Table|EXIF]]<nowiki>]</nowiki></code> table.
  
 
=Syntax=
 
=Syntax=
<syntaxhighlight lang="Python">
+
<source lang="Python">
 
object newexif();
 
object newexif();
</syntaxhighlight>
+
</source>
  
 
=Return value=
 
=Return value=
Line 11: Line 11:
  
 
=Sample=
 
=Sample=
 
+
<source lang="Python" highlight="15">
<syntaxhighlight lang="Python" highlight="15">
 
 
import truxton
 
import truxton
 
from datetime import datetime
 
from datetime import datetime
Line 46: Line 45:
 
if __name__ == "__main__":
 
if __name__ == "__main__":
 
   main()
 
   main()
</syntaxhighlight>
+
</source>

Revision as of 12:24, 22 February 2021

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

Syntax

object newexif();

Return value

An EXIF object

Sample

import truxton
from datetime import datetime
from calendar import timegm

EPOCH_AS_FILETIME = 116444736000000000
HUNDREDS_OF_NANOSECONDS = 10000000

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

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

  exif = file.newexif()

  exif.gpstime = date_to_filetime(datetime.utcnow())
  exif.devicetime = date_to_filetime(datetime.utcnow())
  exif.shuttercount = 42
  exif.make = "Goosungapl"
  exif.model = "BFG-9000"
  exif.bodyserialnumber = "TX010188-PY"
  exif.latitude = 31.554759
  exif.longitude = -97.128955
  exif.altitude = 100
  exif.heading = 300
  exif.focallength = 28.2

  if exif.save() is True:
    print( "New EXIF saved as id " + exif.id)

if __name__ == "__main__":
  main()