|
8 | 8 | zone=sys.argv[3]
|
9 | 9 | l = LocationInfo('wsprep', 'local', zone, lat, lon,)
|
10 | 10 | d = date.today()
|
11 |
| -sun=sun(l.observer, date=d, tzinfo=zone) |
12 |
| -print( str(sun['sunrise'])[11:16] + " " + str(sun['sunset'])[11:16] ) |
| 11 | +# |
| 12 | +# Addition of try: and except * : exception handling for use in high north and south latitudes |
| 13 | +# at times when the sun does not dip more than 6 deg below horizon, or rises above 6 deg below |
| 14 | +# Gwyn G3ZIL 26 July 2023 |
| 15 | +# |
| 16 | +# Complication is that the same exception is raised whether the sun never sets or the sun |
| 17 | +# rises. So look at day of year and which hemisphere in series of four ifs |
| 18 | +# |
| 19 | +# calculate day of year |
| 20 | +today=datetime.datetime.now() |
| 21 | +day_of_year=int(today.strftime('%j')) # day of year as integer |
| 22 | + |
| 23 | +try: |
| 24 | + sun=sun(l.observer, date=d, tzinfo=zone) |
| 25 | + print( str(sun['sunrise'])[11:16] + " " + str(sun['sunset'])[11:16] ) |
| 26 | +except ValueError as e: |
| 27 | + if (('Sun never reaches') or ('Sun is always') in str (e)): # exception raised |
| 28 | + if (lat> 60) and (100 <= day_of_year <=260): # Northern hemisphere summer |
| 29 | + print('00:00 23:59') # it is light all day |
| 30 | + elif (lat >60) and (1 <= day_of_year <=80 or 280 <= day_of_year <366): # Northern hemisphere winter |
| 31 | + print('00:00 00:01') # it is dark all day |
| 32 | + elif (lat< -60) and (100 <= day_of_year <=260): # Southern hemisphere winter |
| 33 | + print('00:00 00:01') # it is dark all day |
| 34 | + elif (lat <-60) and (1 <= day_of_year <=80 or 280 <= day_of_year <366): # Southern hemisphere summer |
| 35 | + print('00:00 23:59') # it is light all day |
| 36 | + else: |
| 37 | + print ('Should never get here given latitude and day of year') |
| 38 | + |
0 commit comments