Guest User

AutoExpand from Category SubCategory FR

a guest
Jul 2nd, 2020
47
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- AutoExpand Category_fr / SubCategory_fr
  2. -- Will look up Category_fr-SubCategory_fr in the the csv list and assign all metadayta if matches
  3. -- Modified by Theo Serror June 3,2020
  4. -- Based on Justin Drury's built-in "AutoExpand from Category SubCategory.lua"
  5.  
  6. allowUndo=true
  7.  
  8. -- [[ ================= HELPER FUNCTIONS ================= ]]--
  9. function table_print (tt, indent, done)
  10. done = done or {}
  11. indent = indent or 0
  12. if type(tt) == "table" then
  13. for key, value in pairs (tt) do
  14. io.write(string.rep (" ", indent)) -- indent it
  15. if type (value) == "table" and not done [value] then
  16. done [value] = true
  17. io.write(string.format("[%s] => table\n", tostring (key)));
  18. io.write(string.rep (" ", indent+4)) -- indent it
  19. io.write("(\n");
  20. table_print (value, indent + 7, done)
  21. io.write(string.rep (" ", indent+4)) -- indent it
  22. io.write(")\n");
  23. else
  24. io.write(string.format("[%s] => %s\n",
  25. tostring (key), tostring(value)))
  26. end
  27. end
  28. else
  29. io.write(tt .. "\n")
  30. end
  31. end
  32.  
  33.  
  34. --[[ ========================================================== ]]--
  35. -- This uses a Lua capability called closure.
  36. function setup()
  37.  
  38. -- put the cat entries in a list I can quickly lookup
  39. local lookupTable={}
  40. _.each(cat_entries,function(entry)
  41. local key=entry['Category_fr']
  42. if key ~='' and entry['SubCategory_fr'] ~='' then
  43. key=key..'-'..entry['SubCategory_fr']
  44. end
  45. print(key)
  46. if key ~='' then
  47. lookupTable[key]=entry
  48. end
  49. end)
  50.  
  51. return function(fileMetadata)
  52. local changedMetadata={}
  53. local key=fileMetadata['Category_fr']
  54. if key ~='' and fileMetadata['SubCategory_fr'] or '' ~='' then
  55. key=key..'-'..fileMetadata['SubCategory_fr']
  56. end
  57.  
  58. if key ~='' then
  59. local csvData=lookupTable[key]
  60. if csvData then
  61. return csvData
  62. end
  63. end
  64. return changedMetadata
  65. end
  66. end
  67. --[[ ========================================================== ]]--
  68. processMetadata=setup()
RAW Paste Data