def fetch_consumption(country_code='ES-CN', session=None): ses = session or Session() elhierro = ElHierro(ses).get() if not elhierro: raise ParserException("ES-CN", "ElHierro not response") granacanaria = GranCanaria(ses).get() if not granacanaria: raise ParserException("ES-CN", "GranCanaria not response") gomera = Gomera(ses).get() if not gomera: raise ParserException("ES-CN", "Gomera not response") lanzarotefuerteventura = LanzaroteFuerteventura(ses).get() if not lanzarotefuerteventura: raise ParserException("ES-CN", "LanzaroteFuerteventura not response") palma = LaPalma(ses).get() if not palma: raise ParserException("ES-CN", "LaPalma not response") tenerife = Tenerife(ses).get() if not tenerife: raise ParserException("ES-CN", "Tenerife not response") ## Compare timestamps ## Raise ParserException if timestamps aren't equals if elhierro.timestamp != granacanaria.timestamp \ and elhierro.timestamp != gomera.timestamp \ and elhierro.timestamp != lanzarotefuerteventura.timestamp \ and elhierro.timestamp != palma.timestamp \ and elhierro.timestamp != tenerife.timestamp: raise ParserException("ES-CN", "Response timestamps aren't equals") demand = round( elhierro.demand + granacanaria.demand + gomera.demand + lanzarotefuerteventura.demand + palma.demand + tenerife.demand, 2) data = { 'countryCode': country_code, 'datetime': get(elhierro.timestamp).datetime, 'consumption': demand, 'source': 'demanda.ree.es' } return data
def fetch_consumption(country_code='ES-CN', session=None): ses = session or session() elhierro = ElHierro(ses).get() if not elhierro: return None granacanaria = GranCanaria(ses).get() if not granacanaria: return None gomera = Gomera(ses).get() if not gomera: return None lanzarotefuerteventura = LanzaroteFuerteventura(ses).get() if not lanzarotefuerteventura: return None palma = LaPalma(ses).get() if not palma: return None tenerife = Tenerife(ses).get() if not tenerife: return None ##Compare timestamps ## Return None if timestamps aren't equals if elhierro.timestamp != granacanaria.timestamp \ and elhierro.timestamp != gomera.timestamp \ and elhierro.timestamp != lanzarotefuerteventura.timestamp \ and elhierro.timestamp != palma.timestamp \ and elhierro.timestamp != tenerife.timestamp: return None demand = round( elhierro.demand + granacanaria.demand + gomera.demand + lanzarotefuerteventura.demand + palma.demand + tenerife.demand, 2) data = { 'countryCode': country_code, 'datetime': get(elhierro.timestamp).datetime, 'consumption': demand, 'source': 'demanda.ree.es' } return data
def fetch_islands_data(country_code, session): data = {} el_hierro_data = ElHierro(session).get_all() if not el_hierro_data: raise ParserException(country_code, "ElHierro not response") else: data.update({'el_hierro': el_hierro_data}) gran_canaria_data = GranCanaria(session).get_all() if not gran_canaria_data: raise ParserException(country_code, "GranCanaria not response") else: data.update({'gran_canaria': gran_canaria_data}) gomera_data = Gomera(session).get_all() if not gomera_data: raise ParserException(country_code, "Gomera not response") else: data.update({'gomera': gomera_data}) lanzarote_fuerteventura_data = LanzaroteFuerteventura(session).get_all() if not lanzarote_fuerteventura_data: raise ParserException(country_code, "LanzaroteFuerteventura not response") else: data.update({'lanzarote_fuerteventura': lanzarote_fuerteventura_data}) la_palma_data = LaPalma(session).get_all() if not la_palma_data: raise ParserException(country_code, "LaPalma not response") else: data.update({'la_palma': la_palma_data}) tenerife_data = Tenerife(session).get_all() if not tenerife_data: raise ParserException(country_code, "Tenerife not response") else: data.update({'tenerife': tenerife_data}) return data
def fetch_island_data(zone_key, session): if zone_key == 'ES-CN-FVLZ': lanzarote_fuerteventura_data = LanzaroteFuerteventura(session).get_all() if not lanzarote_fuerteventura_data: raise ParserException(zone_key, "LanzaroteFuerteventura not response") else: return lanzarote_fuerteventura_data elif zone_key == 'ES-CN-GC': gran_canaria_data = GranCanaria(session).get_all() if not gran_canaria_data: raise ParserException(zone_key, "GranCanaria not response") else: return gran_canaria_data elif zone_key == 'ES-CN-IG': gomera_data = Gomera(session).get_all() if not gomera_data: raise ParserException(zone_key, "Gomera not response") else: return gomera_data elif zone_key == 'ES-CN-LP': la_palma_data = LaPalma(session).get_all() if not la_palma_data: raise ParserException(zone_key, "LaPalma not response") else: return la_palma_data elif zone_key == 'ES-CN-TE': tenerife_data = Tenerife(session).get_all() if not tenerife_data: raise ParserException(zone_key, "Tenerife not response") else: return tenerife_data elif zone_key == 'ES-CN-HI': el_hierro_data = ElHierro(session).get_all() if not el_hierro_data: raise ParserException(zone_key, "ElHierro not response") else: return el_hierro_data else: raise ParserException(zone_key, 'Can\'t read this country code {0}'.format(zone_key))
def fetch_production(country_code='ES-CN', session=None): ses = session or Session() elhierro = ElHierro(ses).get() if not elhierro: raise ParserException("ES-CN", "ElHierro not response") granacanaria = GranCanaria(ses).get() if not granacanaria: raise ParserException("ES-CN", "GranCanaria not response") gomera = Gomera(ses).get() if not gomera: raise ParserException("ES-CN", "Gomera not response") lanzarotefuerteventura = LanzaroteFuerteventura(ses).get() if not lanzarotefuerteventura: raise ParserException("ES-CN", "LanzaroteFuerteventura not response") palma = LaPalma(ses).get() if not palma: raise ParserException("ES-CN", "LaPalma not response") tenerife = Tenerife(ses).get() if not tenerife: raise ParserException("ES-CN", "Tenerife not response") ## Compare timestamps ## Raise ParserException if timestamps aren't equals if elhierro.timestamp != granacanaria.timestamp \ and elhierro.timestamp != gomera.timestamp \ and elhierro.timestamp != lanzarotefuerteventura.timestamp \ and elhierro.timestamp != palma.timestamp \ and elhierro.timestamp != tenerife.timestamp: raise ParserException("ES-CN", "Response timestamps aren't equals") ## Gas production gas_elhierro = elhierro.gas + elhierro.combined gas_granacanaria = granacanaria.gas + granacanaria.combined gas_gomera = gomera.gas + gomera.combined gas_lanzarotefuerteventura = lanzarotefuerteventura.gas + lanzarotefuerteventura.combined gas_palma = palma.gas + palma.combined gas_tenerife = tenerife.gas + tenerife.combined gas_total = gas_elhierro + gas_granacanaria + gas_gomera + gas_lanzarotefuerteventura + gas_palma + gas_tenerife ## Solar production solar_total = elhierro.solar + granacanaria.solar + gomera.solar + lanzarotefuerteventura.solar + palma.solar + tenerife.solar ## Oil production oil_elhierro = elhierro.vapor + elhierro.diesel oil_granacanaria = granacanaria.gas + granacanaria.combined oil_gomera = gomera.gas + gomera.combined oil_lanzarotefuerteventura = lanzarotefuerteventura.gas + lanzarotefuerteventura.combined oil_palma = palma.gas + palma.combined oil_tenerife = tenerife.gas + tenerife.combined oil_total = oil_elhierro + oil_granacanaria + oil_gomera + oil_lanzarotefuerteventura + oil_palma + oil_tenerife ## Wind production wind_total = elhierro.wind + granacanaria.wind + gomera.wind + lanzarotefuerteventura.wind + palma.wind + tenerife.wind ## Hydro production (EL Hierrro is exluded) hydro_total = granacanaria.hydraulic + gomera.hydraulic + lanzarotefuerteventura.hydraulic + palma.hydraulic + tenerife.hydraulic ## Hydro storage hydro_storage = -elhierro.hydraulic data = { 'countryCode': country_code, 'datetime': get(elhierro.timestamp).datetime, 'production': { 'coal': 0.0, 'gas': round(gas_total, 2), 'solar': round(solar_total, 2), 'oil': round(oil_total, 2), 'wind': round(wind_total, 2), 'hydro': round(hydro_total, 2), 'biomass': 0.0, 'nuclear': 0.0, 'geothermal': 0.0, 'unknown': 0.0 }, 'storage': { 'hydro': round(hydro_storage, 2) }, 'source': 'demanda.ree.es', } return data