There are many websites and apps that do this for you already. The website SkyVector will show colored dots that indicate what the airport status is. There is also a ForeFlight app that will show colored dots on their maps. I am not endorsing any products, simply pointing out tools that accomplish what you are asking.
All these companies use information found in AC 00-45H. I added color for clarification.
Personally, I would stay away from getting into the details of what class airspace an airport is currently using. Although, the information can be easily found, it may be a challenge to code successfully. The airspace above an airport can also change depending on whether an control tower is in use, the day of time or other factors.
The other reason, is 91.155(c). Hence, any ceiling below 1,000 FT makes the airport IFR.
Except as provided in §91.157, no person may operate an aircraft beneath the ceiling under VFR within the lateral boundaries of controlled airspace designated to the surface for an airport when the ceiling is less than 1,000 feet.
To answer your other question. The ceiling is defined as the lowest BKN or OVC layer. In your example above, the ceiling is OVC 500.