The problem is where you put the rospy.spin().
rospy.spin() keeps the current thread alive but does not execute any other instructions.
In your example, removing the rospy.spin() command before and after while not rospy.is_shutdown () will run the code I think you want to run.