I am trying to write a script which will fetch the posts which needs to update translation or not translated at all and translate them in bulk in background using the WPML credits I have in my account.
Unfortunately support for custom coding is out of scope of this forum.
However, WPML offers filters and action hooks that can be used in your WordPress theme or plugin to provide correct multilingual support. Browse following resources for more information: