简单日落日出时间计算python库
suntime的Python项目详细描述
太阳时间
简单的日落和日出时间计算python库
安装
使用pip:
pip3 install suntime
或下载并键入:
python3 setup.py install
用法
您可以使用库获取UTC和当地时间日出和日落时间,输入:
importdatetimefromsuntimeimportSun,SunTimeExceptionlatitude=51.21longitude=21.01sun=Sun(latitude,longitude)# Get today's sunrise and sunset in UTCtoday_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 zoneabd=datetime.date(2014,10,3)abd_sr=sun.get_local_sunrise_time(abd)abd_ss=sun.get_local_sunset_time(abd)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.55longitude=0.1sun=Sun(latitude,longitude)try:abd_sr=sun.get_local_sunrise_time(abd)abd_ss=sun.get_local_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')))exceptSunTimeExceptionase:print("Error: {0}.".format(e))
许可证
版权所有©2019 Satagro Sp.Z O.O.和撰稿人:
此文件是python(suntime)suntime库的一部分。
SunTime是自由软件:您可以根据自由软件基金会(free software Foundation)发布的GNU Lesser通用公共许可证(GNU Lesser General Public License)的条款(许可证的第3版或任何更高版本)重新分发和/或修改它
Pun> SunTimes的分布是希望它有用,但没有任何保证;甚至没有对适销性或适合特定用途的默示保证。有关更多详细信息,请参阅GNU Lesser通用公共许可证。您应该已经收到GNU Lesser通用公共许可证的副本以及CAMS工具如果没有,请参阅http://www.gnu.org/licenses/。