Script if no internet switch wifi

can you help me to do a script to switch from wifi1 to wifi2 or vise versa when it detect no internet?