def main(): pihole = ph.PiHole("192.168.0.10") # print(pihole.status, pihole.domain_count, pihole.queries, pihole.blocked, pihole.ads_percentage, #pihole.unique_domains, pihole.forwarded, pihole.cached, pihole.total_clients, pihole.unique_clients, #pihole.total_queries) #weather = WEATHER() #condition = weather.getCondition() #temperature = weather.getTemperature() #print (temperature) weather = WEATHER() myAlarms = [] clock = CLOCK(myAlarms) advice = ADVICE() # allInput = ALLINPUT(clock, myAlarms, weather) controller = CONTROLLER(clock, myAlarms, weather, advice, pihole) controller.startDisplayView()
def get(cache_index, constructor, cache_ttl_seconds=None, **kwargs): """Get a cache with a specified index from the list above. If not initialized, use constructor to initialize it; if cache_ttl_seconds is set, reload it after that period.""" # First try without a lock result = _get(cache_index) if result: return result # Then grab the lock and try again with singletons_lock: result = _get(cache_index) if result: return result else: new_instance = constructor(**kwargs) expiration_time = None if cache_ttl_seconds is not None: expiration_time = CLOCK.now() + timedelta(seconds=cache_ttl_seconds) singletons_map[cache_index] = (new_instance, expiration_time) return new_instance
def _get(cache_index): existing_pair = singletons_map.get(cache_index) if existing_pair and (existing_pair[1] is None or existing_pair[1] >= CLOCK.now()): return existing_pair[0] return None