A well-structured automation script separates logic into functions, puts the entry point in main() called under if __name__ == '__main__':, reads its parameters rather than hard-coding them, logs what it does and handles errors. This makes it testable, reusable and schedulable.
Example
def main():
...
if __name__ == '__main__':
main()