Simple sunset and sunrise time calculation python library
Project description
SunTime
Simple sunset and sunrise time calculation python library.
Installation
Using pip:
pip3 install suntime
Or download and type:
python3 setup.py install
Usage
You can use the library to get UTC and local time sunrise and sunset times typing:
import datetime
from dateutil import tz
from suntime import Sun, SunTimeException
warsaw_lat = 51.21
warsaw_lon = 21.01
sun = Sun(warsaw_lat, warsaw_lon)
# Get today's sunrise and sunset in UTC
today_sr = sun.get_sunrise_time()
today_ss = sun.get_sunset_time()
print('Today at Warsaw the sun raised at {} and get down at {} UTC'.
format(today_sr.strftime('%H:%M'), today_ss.strftime('%H:%M')))
# On a special date in your machine's local time zone
abd = datetime.date(2014, 10, 3)
abd_sr = sun.get_sunrise_time(abd, tz.gettz('Europe/Warsaw'))
abd_ss = sun.get_sunset_time(abd, tz.gettz('Europe/Warsaw'))
print('On {} the sun at Warsaw raised at {} and get down at {}.'.
format(abd, abd_sr.strftime('%H:%M'), abd_ss.strftime('%H:%M')))
# Error handling (no sunset or sunrise on given location)
latitude = 87.55
longitude = 0.1
sun = Sun(latitude, longitude)
try:
abd_sr = sun.get_sunrise_time(abd)
abd_ss = sun.get_sunset_time(abd)
print('On {} at somewhere in the north the sun raised at {} and get down at {}.'.
format(abd, abd_sr.strftime('%H:%M'), abd_ss.strftime('%H:%M')))
except SunTimeException as e:
print("Error: {0}.".format(e))
Testing
To run the tests, type:
pytest tests.py
For linting checks, type:
flake8 .
License
Copyright © 2024 SatAgro Sp. z o.o. and our awesome contributors:
- Andrey Kobyshev (yokotoka)
- Hadrien Bertrand (hbertrand)
- Ingo Randolf (i-n-g-o)
- John Vandenberg (jayvdb)
- Krzysztof Stopa (kstopa)
- Matthias (palto42)
- Muhammad Yasirroni (yasirroni)
This file is part of SunTime library for python (SunTime).
SunTime is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
SunTime is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with CAMS tools. If not, see http://www.gnu.org/licenses/.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file suntime-1.3.2.tar.gz
.
File metadata
- Download URL: suntime-1.3.2.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
4834f7907ad13dbb369904cb5f4376edc0b06c6e8a1cfc0aac1268f64d0ecdcf
|
|
MD5 |
0f6226410557351f4a21786ffade7c79
|
|
BLAKE2b-256 |
15c2326d74790070491bf28e0e304b951f5e47d65c0abfab33677d379117db29
|
File details
Details for the file suntime-1.3.2-py3-none-any.whl
.
File metadata
- Download URL: suntime-1.3.2-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
33ac6ec2a3e14758cc690f7573f689d19c3131a6c9753f1bb54460bd70372ca4
|
|
MD5 |
91a94d4da2a4a6309b9aa8beaa410187
|
|
BLAKE2b-256 |
d1d5bb9997169b8b64d48f9a807fb2ec2413ff5e75c4b77612e75dd0aac8369c
|