#!/usr/bin/env python3 # Challenge 037 # # TASK #2 # Write a script to find out the DayLight gain/loss in the month of December # 2019 as compared to November 2019 in the city of London. You can find out # sunrise and sunset data for November 2019 and December 2019 for London. import re november_data = """ 2019 Sunrise/Sunset Daylength Astronomical Twilight Nautical Twilight Civil Twilight Solar Noon Nov Sunrise Sunset Length Diff. Start End Start End Start End Time Mil. km 1 06:53 ? 16:34 ? 9:40:44 -3:35 05:00 18:27 05:38 17:48 06:18 17:09 11:44 148.491 2 06:55 ? 16:32 ? 9:37:10 -3:33 05:01 18:25 05:40 17:47 06:19 17:07 11:44 148.451 3 06:56 ? 16:30 ? 9:33:38 -3:32 05:03 18:24 05:41 17:45 06:21 17:05 11:44 148.412 4 06:58 ? 16:28 ? 9:30:07 -3:30 05:04 18:22 05:43 17:43 06:23 17:04 11:44 148.373 5 07:00 ? 16:27 ? 9:26:38 -3:29 05:06 18:21 05:45 17:42 06:24 17:02 11:44 148.334 6 07:02 ? 16:25 ? 9:23:11 -3:27 05:07 18:19 05:46 17:40 06:26 17:01 11:44 148.296 7 07:03 ? 16:23 ? 9:19:45 -3:25 05:09 18:18 05:48 17:39 06:28 16:59 11:44 148.258 8 07:05 ? 16:22 ? 9:16:22 -3:23 05:10 18:16 05:49 17:38 06:29 16:58 11:44 148.221 9 07:07 ? 16:20 ? 9:13:01 -3:21 05:12 18:15 05:51 17:36 06:31 16:56 11:44 148.184 10 07:09 ? 16:18 ? 9:09:42 -3:18 05:13 18:14 05:52 17:35 06:32 16:55 11:44 148.148 11 07:10 ? 16:17 ? 9:06:25 -3:16 05:15 18:13 05:54 17:34 06:34 16:53 11:44 148.112 12 07:12 ? 16:15 ? 9:03:11 -3:14 05:16 18:11 05:55 17:32 06:36 16:52 11:44 148.077 13 07:14 ? 16:14 ? 8:59:59 -3:11 05:18 18:10 05:57 17:31 06:37 16:51 11:44 148.043 14 07:16 ? 16:12 ? 8:56:50 -3:09 05:19 18:09 05:58 17:30 06:39 16:49 11:44 148.009 15 07:17 ? 16:11 ? 8:53:44 -3:06 05:20 18:08 06:00 17:29 06:40 16:48 11:45 147.976 16 07:19 ? 16:10 ? 8:50:40 -3:03 05:22 18:07 06:01 17:28 06:42 16:47 11:45 147.944 17 07:21 ? 16:08 ? 8:47:39 -3:00 05:23 18:06 06:03 17:26 06:44 16:46 11:45 147.912 18 07:22 ? 16:07 ? 8:44:42 -2:57 05:25 18:05 06:04 17:25 06:45 16:44 11:45 147.881 19 07:24 ? 16:06 ? 8:41:48 -2:54 05:26 18:04 06:06 17:24 06:47 16:43 11:45 147.850 20 07:26 ? 16:05 ? 8:38:57 -2:50 05:27 18:03 06:07 17:24 06:48 16:42 11:46 147.820 21 07:27 ? 16:04 ? 8:36:09 -2:47 05:29 18:02 06:08 17:23 06:50 16:41 11:46 147.791 22 07:29 ? 16:03 ? 8:33:25 -2:43 05:30 18:01 06:10 17:22 06:51 16:40 11:46 147.762 23 07:31 ? 16:01 ? 8:30:45 -2:40 05:31 18:01 06:11 17:21 06:53 16:39 11:46 147.733 24 07:32 ? 16:00 ? 8:28:09 -2:36 05:33 18:00 06:13 17:20 06:54 16:39 11:47 147.705 25 07:34 ? 15:59 ? 8:25:36 -2:32 05:34 17:59 06:14 17:19 06:56 16:38 11:47 147.677 26 07:35 ? 15:59 ? 8:23:08 -2:28 05:35 17:59 06:15 17:19 06:57 16:37 11:47 147.650 27 07:37 ? 15:58 ? 8:20:44 -2:23 05:37 17:58 06:17 17:18 06:58 16:36 11:47 147.623 28 07:38 ? 15:57 ? 8:18:24 -2:19 05:38 17:57 06:18 17:17 07:00 16:35 11:48 147.596 29 07:40 ? 15:56 ? 8:16:09 -2:15 05:39 17:57 06:19 17:17 07:01 16:35 11:48 147.570 30 07:41 ? 15:55 ? 8:13:59 -2:10 05:40 17:57 06:20 17:16 07:02 16:34 11:49 147.544 * All times are local time for London. They take into account refraction. Dates are based on the Gregorian calendar. """ december_data = """ 2019 Sunrise/Sunset Daylength Astronomical Twilight Nautical Twilight Civil Twilight Solar Noon Dec Sunrise Sunset Length Diff. Start End Start End Start End Time Mil. km 1 07:43 ? 15:55 ? 8:11:53 -2:05 05:41 17:56 06:22 17:16 07:04 16:34 11:49 147.518 2 07:44 ? 15:54 ? 8:09:53 -2:00 05:42 17:56 06:23 17:15 07:05 16:33 11:49 147.493 3 07:46 ? 15:53 ? 8:07:57 -1:55 05:44 17:55 06:24 17:15 07:06 16:33 11:50 147.469 4 07:47 ? 15:53 ? 8:06:07 -1:50 05:45 17:55 06:25 17:15 07:08 16:32 11:50 147.446 5 07:48 ? 15:53 ? 8:04:22 -1:45 05:46 17:55 06:26 17:14 07:09 16:32 11:50 147.423 6 07:49 ? 15:52 ? 8:02:42 -1:39 05:47 17:55 06:27 17:14 07:10 16:32 11:51 147.400 7 07:51 ? 15:52 ? 8:01:08 -1:34 05:48 17:55 06:28 17:14 07:11 16:31 11:51 147.379 8 07:52 ? 15:51 ? 7:59:40 -1:28 05:49 17:54 06:29 17:14 07:12 16:31 11:52 147.358 9 07:53 ? 15:51 ? 7:58:17 -1:22 05:50 17:54 06:30 17:14 07:13 16:31 11:52 147.338 10 07:54 ? 15:51 ? 7:57:01 -1:16 05:51 17:54 06:31 17:14 07:14 16:31 11:53 147.319 11 07:55 ? 15:51 ? 7:55:50 -1:10 05:52 17:54 06:32 17:14 07:15 16:31 11:53 147.301 12 07:56 ? 15:51 ? 7:54:45 -1:04 05:52 17:54 06:33 17:14 07:16 16:31 11:54 147.283 13 07:57 ? 15:51 ? 7:53:46 -0:58 05:53 17:55 06:34 17:14 07:17 16:31 11:54 147.267 14 07:58 ? 15:51 ? 7:52:54 -0:52 05:54 17:55 06:35 17:14 07:18 16:31 11:54 147.251 15 07:59 ? 15:51 ? 7:52:08 -0:46 05:55 17:55 06:36 17:14 07:19 16:31 11:55 147.237 16 08:00 ? 15:51 ? 7:51:28 -0:39 05:56 17:55 06:36 17:14 07:19 16:31 11:55 147.223 17 08:00 ? 15:51 ? 7:50:54 -0:33 05:56 17:56 06:37 17:15 07:20 16:32 11:56 147.210 18 08:01 ? 15:52 ? 7:50:27 -0:27 05:57 17:56 06:38 17:15 07:21 16:32 11:56 147.198 19 08:02 ? 15:52 ? 7:50:06 -0:20 05:58 17:56 06:38 17:15 07:22 16:32 11:57 147.187 20 08:02 ? 15:52 ? 7:49:52 -0:14 05:58 17:57 06:39 17:16 07:22 16:33 11:57 147.177 21 08:03 ? 15:53 ? 7:49:44 -0:07 05:59 17:57 06:40 17:16 07:23 16:33 11:58 147.167 22 08:04 ? 15:53 ? 7:49:43 -0:01 05:59 17:58 06:40 17:17 07:23 16:34 11:58 147.158 23 08:04 ? 15:54 ? 7:49:49 +0:05 06:00 17:58 06:41 17:17 07:24 16:34 11:59 147.149 24 08:04 ? 15:54 ? 7:50:01 +0:11 06:00 17:59 06:41 17:18 07:24 16:35 11:59 147.141 25 08:05 ? 15:55 ? 7:50:19 +0:18 06:01 17:59 06:41 17:19 07:25 16:35 12:00 147.133 26 08:05 ? 15:56 ? 7:50:44 +0:24 06:01 18:00 06:42 17:19 07:25 16:36 12:00 147.126 27 08:05 ? 15:57 ? 7:51:15 +0:31 06:01 18:01 06:42 17:20 07:25 16:37 12:01 147.120 28 08:06 ? 15:57 ? 7:51:53 +0:37 06:01 18:01 06:42 17:21 07:25 16:38 12:01 147.114 29 08:06 ? 15:58 ? 7:52:37 +0:44 06:02 18:02 06:42 17:21 07:26 16:38 12:02 147.109 30 08:06 ? 15:59 ? 7:53:28 +0:50 06:02 18:03 06:43 17:22 07:26 16:39 12:02 147.104 31 08:06 ? 16:00 ? 7:54:24 +0:56 06:02 18:04 06:43 17:23 07:26 16:40 12:03 147.100 * All times are local time for London. They take into account refraction. Dates are based on the Gregorian calendar. """ def parse_sun_length(data): sun_length_seconds = 0 for line in data.split("\n"): if m := re.match(r"^(\d+)", line): day = int(m.group(1)) # check only 30 days so that periods are same if 1 <= day <= 30: if m := re.search(r"\s(\d+):(\d+):(\d+)\s", line): hour = int(m.group(1)) minute = int(m.group(2)) second = int(m.group(3)) day_seconds = 3600*hour+60*minute+second sun_length_seconds += day_seconds return sun_length_seconds november_sun_length = parse_sun_length(november_data) december_sun_length = parse_sun_length(december_data) print("{:.1f} minutes gained".format((december_sun_length-november_sun_length)/60))