Python Sample Tag Notification ETL

From truxwiki.com
Jump to navigation Jump to search

This sample shows the steps needed to implement an ETL that gets called when a user tags something in the desktop. Add your ETL to the Truxton Service for it to automatically start with the other ETL processes.

Source Code

 1 import sys
 2 sys.path.append('C:/Program Files/Truxton/SDK')
 3 import truxton
 4 
 5 def main() -> None:
 6 
 7   arabic  = "409544A9-7D0D-706F-3C30-5A478C264FF3"
 8   chinese = "0139FC29-A050-CA68-BF88-C6AD83F27AD1"
 9   russian = "BD35D2C1-8EAE-1FAA-94AE-C890C7B7BFDD"
10 
11   etl = truxton.etl()
12   etl.name = "Tag Exploitation"
13   etl.description = "This gets pinged when someone tags something"
14   etl.queue = "iwanttags"
15   etl.stage = 255
16   etl.addtype(truxton.Type_Tag)
17 
18   message = etl.getmessage()
19 
20   while message is not None:   
21     if message.depotoffset == truxton.OBJECT_TYPE_FILE:
22       if message.parentid in [ arabic, chinese, russian ]:
23          print( "File " + message.fileid + " needs translating." )
24 
25     message = etl.getmessage()
26 
27   return None
28 
29 if __name__ == "__main__":
30     sys.exit(main())

Code Walkthrough

The above code shows how to create an ETL process that will wait for files to be tagged with "Arabic", "Chinese" or "Russian."

Line 2 appends the Truxton SDK folder to Python's path used to find import modules.

Line 3 imports the Truxton Python module

Lines 7-9 store the identifiers for the desired tags. These must be in UPPER CASE LETTERS. These identifiers correspond to the [ID] column of the [Tag] table in the database.

Lines 11-16 setup the ETL. The message queue name will be "iwanttags", we are an ignorable stage and want to receive Type_Tag messages.

Line 18 starts the ETL logic and waits until a message arrives on the "iwanttags" queue.

Line 21 checks to see if the thing being tagged in Truxton is a file. We are parsing a Tag message so the data fields in the message object have been repurposed.

Line 22 checks the tag identifier to see if it is one of the desired tags.

Line 23 prints the identifier of the file that needs translating. This identifier corresponds to the [ID] column of the [File] table in the database.

Line 25 completes the loop by getting another message from the "iwanttags" message queue.