本文整理汇总了Python中astral.Astral.depression方法的典型用法代码示例。如果您正苦于以下问题:Python Astral.depression方法的具体用法?Python Astral.depression怎么用?Python Astral.depression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astral.Astral
的用法示例。
在下文中一共展示了Astral.depression方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ics
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import depression [as 别名]
def ics():
astral = Astral()
astral.solar_depression = "civil"
astral.depression = 6.0
city = astral["Toronto"]
cal = Calendar()
cal.add("prodid", "-//Time of Day//time-of-day.herokuapp.com//")
cal.add("version", "2.0")
today = datetime.date.today()
for x in range(-7, 8):
date = today + datetime.timedelta(days=x)
sun = city.sun(date=date, local=True)
for summary, time in sun.items():
event = Event()
event.add("summary", summary.capitalize())
event.add("dtstart", time)
event.add("dtend", time)
event.add("dtstamp", time)
cal.add_component(event)
resp = make_response(cal.to_ical())
resp.headers["Content-Disposition"] = "attachment; filename=time-of-day.ics"
resp.headers["Content-Type"] = "text/calendar"
return resp
示例2: api_v1
# 需要导入模块: from astral import Astral [as 别名]
# 或者: from astral.Astral import depression [as 别名]
def api_v1():
astral = Astral()
astral.solar_depression = "civil"
astral.depression = 6.0
city = astral["Toronto"]
response = {
"is_day": False,
"is_night": False,
"is_civil_twlight": False,
"is_nautical_twlight": False,
"is_astronomical_twilight": False,
"is_blue_hour": False,
"is_golden_hour": False,
"solar_zenith_angle": city.solar_zenith(),
"solar_elevation_angle": city.solar_elevation(),
"solar_azimuth_angle": city.solar_azimuth(),
"times_of_day": city.sun(),
}
current_datetime = datetime.datetime.now(city.tz)
if city.sunrise() < current_datetime < city.sunset():
response["is_day"] = True
else:
response["is_night"] = True
if -6 <= city.solar_zenith() <= 0:
response["is_civil_twlight"] = True
response["is_day"] = False
response["is_night"] = False
elif -12 <= city.solar_zenith() <= -6:
response["is_nautical_twlight"] = True
response["is_day"] = False
response["is_night"] = False
elif -18 <= city.solar_zenith() <= -12:
response["is_astronomical_twilight"] = True
response["is_day"] = False
response["is_night"] = False
if -6 <= city.solar_zenith() <= -4:
response["is_blue_hour"] = True
elif -4 <= city.solar_zenith() <= 6:
response["is_golden_hour"] = True
if 0 <= city.moon_phase() < 7:
response["moon_phase"] = "new-moon"
elif 7 <= city.moon_phase() < 14:
response["moon_phase"] = "first-quarter"
elif 14 <= city.moon_phase() < 21:
response["moon_phase"] = "full-moon"
elif 21 <= city.moon_phase():
response["moon_phase"] = "last-quarter"
return jsonify(response)