Similar setup here - nothing against you personally, it's just that each time I work through a "person got a mountain of code from an LLM" post and try to guide them through all the things it did wrong makes me feel like Sisyphus.
Top level notes:
- You should only rarely need to import anything in small Ignition scripts. Any imports you do use, you should be judicious about.
- You should never import
systemor anything from system. - You should never use Jython's
datetimelibrary. - You should (almost) never have to import core Java classes like
DateandString
- You should never import
- Defining an
email_historian_data_report()function only to call it in the same file is totally pointless. If you're going to define this as a function, it should be in the project library, and it should accept useful parameters (potentially with default values). whileloops are rarer than imports and should also almost never be used.system.gui.warningBoxis a Vision only function that precludes this script from working in Perspective or being called from anywhere else in Ignition.- Logging statements should be called with
infofvariants to do string formatting lazily, for the sake of performance. - There's no need to import
arrayor coerce the Jython string into a Java string in order to pass it to the attachment parameter - A
try/catch Exceptionaround the whole block is only going to cause you grief troubleshooting, as it won't catch Java exceptions and it throws away the stacktrace, the most useful element for troubleshooting.