Created
September 8, 2021 09:57
-
-
Save MocoNinja/a7d704159b339f53e5db2f173909caf0 to your computer and use it in GitHub Desktop.
Pruebas python timezones / detectar puestas de sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:alpine | |
ADD requirements.txt . | |
RUN pip install -r requirements.txt | |
ADD main.py . | |
ENV TZ Europe/Madrid | |
CMD ["python", "main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from suntime import Sun | |
from datetime import datetime | |
local_timezone = datetime.utcnow().astimezone().tzinfo | |
latitude = 41.64496981020947 | |
longitude = -0.8994023711401836 | |
sun = Sun(latitude, longitude) | |
# Get today's sunrise and sunset in UTC | |
today_sr = sun.get_sunrise_time() | |
today_ss = sun.get_sunset_time() | |
print('Today at Zaragoza the sun raised at {} and get down at {} UTC'. | |
format(today_sr.strftime('%H:%M'), today_ss.strftime('%H:%M'))) | |
today_sr_local = today_sr.astimezone(local_timezone) | |
today_ss_local = today_ss.astimezone(local_timezone) | |
print('Today at Zaragoza the sun raised at {} and get down at {} {}'. | |
format(today_sr_local.strftime('%H:%M'), today_ss_local.strftime('%H:%M'), local_timezone)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suntime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment