48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
#from suntime import Sun
|
|
#from datetime import datetime, timedelta
|
|
#import pytz
|
|
|
|
#latitude = YOUR_LATITUDE
|
|
#longitude = YOUR_LONGITUDE
|
|
|
|
|
|
|
|
|
|
|
|
#sun = Sun(latitude, longitude)
|
|
#tz = pytz.timezone(timezone)
|
|
|
|
# Get yesterday's date and time
|
|
#yesterday = datetime.now(tz) - timedelta(days=1)
|
|
#sunrise_time = sun.get_sunrise_time(yesterday).astimezone(tz)
|
|
|
|
# Print the sunrise time
|
|
#print(sunrise_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
|
|
|
|
|
from datetime import datetime, timedelta
|
|
import pytz
|
|
from suntime import Sun
|
|
|
|
# Example coordinates (e.g., New York City)
|
|
latitude = re.dacted
|
|
longitude = re.dacted
|
|
|
|
|
|
# Define the timezone
|
|
tz = pytz.timezone('America/New_York')
|
|
|
|
# Create a Sun object with the given latitude and longitude
|
|
sun = Sun(latitude, longitude)
|
|
|
|
# Get today's date and time in the desired timezone
|
|
now = datetime.now(tz)
|
|
|
|
# Get today's sunrise time in UTC and convert it to the desired timezone
|
|
sunrise_utc = sun.get_sunrise_time(now)
|
|
sunrise_time = sunrise_utc.astimezone(tz)
|
|
|
|
# Print the sunrise time in the desired format
|
|
print(sunrise_time.strftime('%Y-%m-%d %H:%M:%S'))
|