gpt4 book ai didi

python - Python 中的日出和日落时间

转载 作者:太空狗 更新时间:2023-10-30 00:34:45 25 4
gpt4 key购买 nike

我目前正在从事一个项目,当某些与光相关的事件被触发时通知用户。我已经完成了与光相关的部分。因此,我需要找到一种在 python 中检索日出和日落时间的有效方法,因为整个脚本都是用 python 编写的。我知道有几个其他语言的库,我想知道在 python 中最方便的方法是什么。

我想这看起来很像:

if(sunrise<T<sunset) and (light<threshold):
notifyUser()

如果有任何帮助,我将不胜感激。

最佳答案

查看 astral .这是一个稍微修改过的 example from their docs :

>>> from astral import Astral
>>> city_name = 'London'
>>> a = Astral()
>>> a.solar_depression = 'civil'
>>> city = a[city_name]
>>> sun = city.sun(date=datetime.date(2009, 4, 22), local=True)

>>> if (sun['sunrise'] < T < sun['sunset']) and (light < threshold):
>>> notifyUser()

如果您使用类似此示例的内容,请记住更改提供给 city.suncity_name 和日期。

关于python - Python 中的日出和日落时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38986527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com