Skip to content

Instantly share code, notes, and snippets.

@MocoNinja
Created September 8, 2021 09:57
Show Gist options
  • Save MocoNinja/a7d704159b339f53e5db2f173909caf0 to your computer and use it in GitHub Desktop.
Save MocoNinja/a7d704159b339f53e5db2f173909caf0 to your computer and use it in GitHub Desktop.
Pruebas python timezones / detectar puestas de sol
FROM python:alpine
ADD requirements.txt .
RUN pip install -r requirements.txt
ADD main.py .
ENV TZ Europe/Madrid
CMD ["python", "main.py"]
#!/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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment