def main(): loc = get_loc_from_ip() loc = json.loads(loc.text) # loc['latitude'], loc['longitude'] = (float(x) for x in loc['loc'].strip().split(',')) # loc['time_zone'] = tzlocal.get_localzone().zone # print(loc['ip']) try: location = Location() location.name = loc['country'] location.region = loc['country_iso'] location.latitude = loc['latitude'] location.longitude = loc['longitude'] location.timezone = loc['time_zone'] except ValueError as e: logger.error(str(e)) return sunrise = location.sun()['sunrise'].replace(second=0) + timedelta( minutes=0) sunset = location.sun()['sunset'].replace(second=0) + timedelta(minutes=0) today = datetime.now().astimezone( pytz.timezone("Asia/Yerevan")) + timedelta(minutes=0) dawn = sunrise.astimezone( pytz.timezone("Asia/Yerevan")).strftime('%H:%M:%S') dusk = sunset.astimezone( pytz.timezone("Asia/Yerevan")).strftime('%H:%M:%S') now = today.strftime('%H:%M:%S') print(f'Dawn: {dawn}') print(f'Dusk: {dusk}') print(f'Now: {now}') print( f"You are in {location.name} and the timezone is {location.timezone}") if now < dawn: print("oh still dark") os.system( "gsettings set org.gnome.desktop.interface gtk-theme 'Mc-OS-CTLina-Gnome-Dark-1.3.2'" ) elif dawn < now < dusk: print("it a brand new day") os.system( "gsettings set org.gnome.desktop.interface gtk-theme 'McOS-CTLina-Gnome-1.3.2'" ) else: print("oh is dark") os.system( "gsettings set org.gnome.desktop.interface gtk-theme 'Mc-OS-CTLina-Gnome-Dark-1.3.2'" ) return sunrise.astimezone( pytz.timezone("Asia/Yerevan")), sunset.astimezone( pytz.timezone("Asia/Yerevan"))
#input files: weather_irradiation = 'input/weather/solarirradiation_twenthe.csv' weather_timebaseDataset = 3600 #in seconds per interval #Simulation: #number of days to simulate and skipping of initial days. Simulation starts at Sunday January 1. numDays = 365 # number of days startDay = 0 # Initial day #Select the geographic location. Refer to the Astral plugin to see available locations (or give a lon+lat) # Use e.g. https://www.latlong.net/ location = Location() location.solar_depression = 'civil' location.latitude = 52.239095 location.longitude = 6.857018 location.timezone = 'Europe/Amsterdam' location.elevation = 0 #Select the devices in the neighbourhood #Devices #Scale overall consumption: consumptionFactor = 1.0 #consumption was a bit too high # Penetration of emerging technology in percentages # all values must be between 0-100 # These indicate what percentage of the houses has a certain device # Electric mobility, restriction that the sum <= 100 # Note, households with larger driving distances will receive EVs first
def test_SetLongitudeString(self): loc = Location() loc.longitude = "24°28'S" assert loc.longitude == pytest.approx(-24.46666666666666)
def test_SetBadLongitudeString(self): loc = Location() with pytest.raises(ValueError): loc.longitude = "wibble"
def test_SetLongitudeFloat(self): loc = Location() loc.longitude = 24.0 assert loc.longitude == 24.0