Exemplo n.º 1
0
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"))
Exemplo n.º 2
0
 def test_TimezoneName(self):
     """Test the default timezone and that the timezone is changeable"""
     c = Location()
     assert c.timezone == "Europe/London"
     c.name = "Asia/Riyadh"
     assert c.name == "Asia/Riyadh"
Exemplo n.º 3
0
 def test_Name(self):
     """Test the default name and that the name is changeable"""
     c = Location()
     assert c.name == "Greenwich"
     c.name = "Köln"
     assert c.name == "Köln"