Heads up for anyone thinking about trying this setup: this will make internet access in a daily driver so slow you can't do anything. Seriously, bouncing your traffic through Tor is already slow, but forcing a new IP switch every 5 seconds completely breaks modern internet protocols. Every time the IP changes, your connections drop and reset. You won't even be able to finish loading a basic webpage before it times out.
On top of the terrible speeds, running random Python scripts from GitHub that mess with your OS firewalls and iptables as root is a massive security risk. It gives you a false sense of security while actually leaving you wide open to DNS leaks.
If you actually need anonymity, just use the official Tor Browser or boot into something like Tails. Don't completely nuke your daily system's usability and network for this.