I'm new to Python so please be kind.  I have basic code working to know when the input state of #18 on the RPi GPIO is such that a switch closed.  What I'd like is the best (easiest) method to capture the time when the switch is closed and then not closed (opened).
My end objective is to write to a file when the sail switch closes and then when it opens to a data file to monitor when there is air flow indicating the A/C is running.  I already have the openweathermap API working to gather the temperature and a print of a literal when the switch is closed which just keeps redisplaying in the while loop.  My time.sleep will be 60 seconds.  The file will eventually have all of the start/stop times for several days as well as the temperature.
You if you want to measure time delta between open/close you can use time module, more specific time.time() function. If you want to record date and time of switching, use datetime module with datetime.datetime.now() function.
In a while True loop reading a RPi GPIO need the time a switch was closed and then when the state changed to open