Using the RubySunrise gem

require 'solareventcalculator'
require 'geocoder'
require 'dynarex'

year = '2017'
a = (Date.parse(year + ' Jan')...Date.parse(year.succ + ' Jan')).to_a      
g = Geocoder.search('edinburgh')

times = a.inject({}) do |r, date|

  calc = SolarEventCalculator.new(date, *g[0].coordinates)

  a2 = %w(sunrise sunset).map do |event|
    calc.method('compute_utc_official_'.+(event).to_sym).call.strftime("%H:%M")
  end

  r.merge(date.strftime("%d %b") => a2)
end

dx = Dynarex.new 'times[title, tags, event_title]/day(date, sunrise, sunset)'
dx.title = "Edinburgh sunrise sunset times " + year
dx.tags = "edinburgh times sunrise sunset %s" % [year]
dx.delimiter = ' '

times.each {|k,v| dx.create date: k, sunrise: v[0], sunset: v[1] } 
File.write "edi-sunrise-#{year}.txt", dx.to_s

The above code generates the sunrise and sunset times for Edinburgh 2017.

Output:

<?dynarex schema="times[title, tags, event_title]/day(date, sunrise, sunset)" delimiter=" "?>
title: Edinburgh sunrise sunset times 2017
tags: edinburgh times sunrise sunset 2017

01 Jan 08:43 15:49
02 Jan 08:43 15:50
03 Jan 08:43 15:51
04 Jan 08:42 15:52
05 Jan 08:42 15:54
06 Jan 08:41 15:55
07 Jan 08:41 15:57
08 Jan 08:40 15:58
09 Jan 08:39 16:00
10 Jan 08:39 16:02
11 Jan 08:38 16:03
12 Jan 08:37 16:05
13 Jan 08:36 16:07
14 Jan 08:35 16:08
15 Jan 08:34 16:10
16 Jan 08:33 16:12
17 Jan 08:31 16:14
18 Jan 08:30 16:16
19 Jan 08:29 16:18
20 Jan 08:28 16:20
21 Jan 08:26 16:22
22 Jan 08:25 16:24
23 Jan 08:23 16:26
24 Jan 08:22 16:28
25 Jan 08:20 16:30
26 Jan 08:18 16:32
27 Jan 08:17 16:34
28 Jan 08:15 16:36
29 Jan 08:13 16:39
30 Jan 08:12 16:41
31 Jan 08:10 16:43
01 Feb 08:08 16:45
02 Feb 08:06 16:47
03 Feb 08:04 16:49
04 Feb 08:02 16:52
05 Feb 08:00 16:54
06 Feb 07:58 16:56
07 Feb 07:56 16:58
08 Feb 07:54 17:00
09 Feb 07:52 17:02
10 Feb 07:50 17:05
11 Feb 07:47 17:07
12 Feb 07:45 17:09
13 Feb 07:43 17:11
14 Feb 07:41 17:13
15 Feb 07:38 17:16
16 Feb 07:36 17:18
17 Feb 07:34 17:20
18 Feb 07:31 17:22
19 Feb 07:29 17:24
20 Feb 07:27 17:27
21 Feb 07:24 17:29
22 Feb 07:22 17:31
23 Feb 07:20 17:33
24 Feb 07:17 17:35
25 Feb 07:15 17:37
26 Feb 07:12 17:39
27 Feb 07:10 17:42
28 Feb 07:07 17:44
01 Mar 07:05 17:46
02 Mar 07:02 17:48
03 Mar 07:00 17:50
04 Mar 06:57 17:52
05 Mar 06:55 17:54
06 Mar 06:52 17:56
07 Mar 06:50 17:58
08 Mar 06:47 18:01
09 Mar 06:44 18:03
10 Mar 06:42 18:05
11 Mar 06:39 18:07
12 Mar 06:37 18:09
13 Mar 06:34 18:11
14 Mar 06:31 18:13
15 Mar 06:29 18:15
16 Mar 06:26 18:17
17 Mar 06:23 18:19
18 Mar 06:21 18:21
19 Mar 06:18 18:23
20 Mar 06:16 18:25
21 Mar 06:13 18:27
22 Mar 06:10 18:29
23 Mar 06:08 18:31
24 Mar 06:05 18:34
25 Mar 06:02 18:36
26 Mar 06:00 18:38
27 Mar 05:57 18:40
28 Mar 05:55 18:42
29 Mar 05:52 18:44
30 Mar 05:49 18:46
31 Mar 05:47 18:48
01 Apr 05:44 18:50
02 Apr 05:41 18:52
03 Apr 05:39 18:54
04 Apr 05:36 18:56
05 Apr 05:33 18:58
06 Apr 05:31 19:00
07 Apr 05:28 19:02
08 Apr 05:26 19:04
09 Apr 05:23 19:06
10 Apr 05:21 19:08
11 Apr 05:18 19:10
12 Apr 05:15 19:12
13 Apr 05:13 19:14
14 Apr 05:10 19:16
15 Apr 05:08 19:18
16 Apr 05:05 19:20
17 Apr 05:03 19:22
18 Apr 05:00 19:24
19 Apr 04:58 19:26
20 Apr 04:55 19:28
21 Apr 04:53 19:30
22 Apr 04:50 19:32
23 Apr 04:48 19:34
24 Apr 04:46 19:36
25 Apr 04:43 19:38
26 Apr 04:41 19:41
27 Apr 04:39 19:43
28 Apr 04:36 19:45
29 Apr 04:34 19:47
30 Apr 04:32 19:49
01 May 04:29 19:51
02 May 04:27 19:53
03 May 04:25 19:55
04 May 04:23 19:57
05 May 04:20 19:59
06 May 04:18 20:01
07 May 04:16 20:03
08 May 04:14 20:04
09 May 04:12 20:06
10 May 04:10 20:08
11 May 04:08 20:10
12 May 04:06 20:12
13 May 04:04 20:14
14 May 04:02 20:16
15 May 04:00 20:18
16 May 03:58 20:20
17 May 03:57 20:22
18 May 03:55 20:23
19 May 03:53 20:25
20 May 03:51 20:27
21 May 03:50 20:29
22 May 03:48 20:30
23 May 03:47 20:32
24 May 03:45 20:34
25 May 03:44 20:35
26 May 03:42 20:37
27 May 03:41 20:39
28 May 03:40 20:40
29 May 03:38 20:42
30 May 03:37 20:43
31 May 03:36 20:44
01 Jun 03:35 20:46
02 Jun 03:34 20:47
03 Jun 03:33 20:48
04 Jun 03:32 20:50
05 Jun 03:31 20:51
06 Jun 03:30 20:52
07 Jun 03:29 20:53
08 Jun 03:29 20:54
09 Jun 03:28 20:55
10 Jun 03:28 20:56
11 Jun 03:27 20:57
12 Jun 03:27 20:58
13 Jun 03:26 20:58
14 Jun 03:26 20:59
15 Jun 03:26 21:00
16 Jun 03:25 21:00
17 Jun 03:25 21:01
18 Jun 03:25 21:01
19 Jun 03:25 21:02
20 Jun 03:25 21:02
21 Jun 03:26 21:02
22 Jun 03:26 21:02
23 Jun 03:26 21:03
24 Jun 03:26 21:03
25 Jun 03:27 21:03
26 Jun 03:27 21:02
27 Jun 03:28 21:02
28 Jun 03:28 21:02
29 Jun 03:29 21:02
30 Jun 03:30 21:01
01 Jul 03:31 21:01
02 Jul 03:31 21:01
03 Jul 03:32 21:00
04 Jul 03:33 20:59
05 Jul 03:34 20:59
06 Jul 03:35 20:58
07 Jul 03:36 20:57
08 Jul 03:38 20:56
09 Jul 03:39 20:55
10 Jul 03:40 20:54
11 Jul 03:41 20:53
12 Jul 03:43 20:52
13 Jul 03:44 20:51
14 Jul 03:45 20:50
15 Jul 03:47 20:49
16 Jul 03:48 20:47
17 Jul 03:50 20:46
18 Jul 03:51 20:45
19 Jul 03:53 20:43
20 Jul 03:55 20:42
21 Jul 03:56 20:40
22 Jul 03:58 20:39
23 Jul 04:00 20:37
24 Jul 04:01 20:35
25 Jul 04:03 20:34
26 Jul 04:05 20:32
27 Jul 04:07 20:30
28 Jul 04:08 20:28
29 Jul 04:10 20:26
30 Jul 04:12 20:24
31 Jul 04:14 20:22
01 Aug 04:16 20:20
02 Aug 04:18 20:18
03 Aug 04:19 20:16
04 Aug 04:21 20:14
05 Aug 04:23 20:12
06 Aug 04:25 20:10
07 Aug 04:27 20:08
08 Aug 04:29 20:06
09 Aug 04:31 20:04
10 Aug 04:33 20:01
11 Aug 04:35 19:59
12 Aug 04:37 19:57
13 Aug 04:39 19:55
14 Aug 04:41 19:52
15 Aug 04:43 19:50
16 Aug 04:44 19:48
17 Aug 04:46 19:45
18 Aug 04:48 19:43
19 Aug 04:50 19:40
20 Aug 04:52 19:38
21 Aug 04:54 19:35
22 Aug 04:56 19:33
23 Aug 04:58 19:31
24 Aug 05:00 19:28
25 Aug 05:02 19:26
26 Aug 05:04 19:23
27 Aug 05:06 19:20
28 Aug 05:08 19:18
29 Aug 05:10 19:15
30 Aug 05:12 19:13
31 Aug 05:14 19:10
01 Sep 05:16 19:08
02 Sep 05:18 19:05
03 Sep 05:20 19:03
04 Sep 05:22 19:00
05 Sep 05:24 18:57
06 Sep 05:26 18:55
07 Sep 05:27 18:52
08 Sep 05:29 18:49
09 Sep 05:31 18:47
10 Sep 05:33 18:44
11 Sep 05:35 18:42
12 Sep 05:37 18:39
13 Sep 05:39 18:36
14 Sep 05:41 18:34
15 Sep 05:43 18:31
16 Sep 05:45 18:28
17 Sep 05:47 18:26
18 Sep 05:49 18:23
19 Sep 05:51 18:20
20 Sep 05:53 18:18
21 Sep 05:55 18:15
22 Sep 05:57 18:12
23 Sep 05:59 18:10
24 Sep 06:01 18:07
25 Sep 06:03 18:04
26 Sep 06:04 18:02
27 Sep 06:06 17:59
28 Sep 06:08 17:56
29 Sep 06:10 17:54
30 Sep 06:12 17:51
01 Oct 06:14 17:49
02 Oct 06:16 17:46
03 Oct 06:18 17:43
04 Oct 06:20 17:41
05 Oct 06:22 17:38
06 Oct 06:24 17:35
07 Oct 06:26 17:33
08 Oct 06:28 17:30
09 Oct 06:30 17:28
10 Oct 06:32 17:25
11 Oct 06:34 17:23
12 Oct 06:36 17:20
13 Oct 06:38 17:18
14 Oct 06:41 17:15
15 Oct 06:43 17:13
16 Oct 06:45 17:10
17 Oct 06:47 17:08
18 Oct 06:49 17:05
19 Oct 06:51 17:03
20 Oct 06:53 17:00
21 Oct 06:55 16:58
22 Oct 06:57 16:55
23 Oct 06:59 16:53
24 Oct 07:01 16:51
25 Oct 07:03 16:48
26 Oct 07:05 16:46
27 Oct 07:08 16:44
28 Oct 07:10 16:41
29 Oct 07:12 16:39
30 Oct 07:14 16:37
31 Oct 07:16 16:35
01 Nov 07:18 16:33
02 Nov 07:20 16:30
03 Nov 07:22 16:28
04 Nov 07:25 16:26
05 Nov 07:27 16:24
06 Nov 07:29 16:22
07 Nov 07:31 16:20
08 Nov 07:33 16:18
09 Nov 07:35 16:16
10 Nov 07:37 16:14
11 Nov 07:39 16:12
12 Nov 07:41 16:10
13 Nov 07:44 16:09
14 Nov 07:46 16:07
15 Nov 07:48 16:05
16 Nov 07:50 16:03
17 Nov 07:52 16:02
18 Nov 07:54 16:00
19 Nov 07:56 15:59
20 Nov 07:58 15:57
21 Nov 08:00 15:56
22 Nov 08:02 15:54
23 Nov 08:04 15:53
24 Nov 08:06 15:51
25 Nov 08:07 15:50
26 Nov 08:09 15:49
27 Nov 08:11 15:48
28 Nov 08:13 15:47
29 Nov 08:15 15:46
30 Nov 08:16 15:45
01 Dec 08:18 15:44
02 Dec 08:20 15:43
03 Dec 08:21 15:42
04 Dec 08:23 15:41
05 Dec 08:24 15:41
06 Dec 08:26 15:40
07 Dec 08:27 15:39
08 Dec 08:29 15:39
09 Dec 08:30 15:39
10 Dec 08:31 15:38
11 Dec 08:33 15:38
12 Dec 08:34 15:38
13 Dec 08:35 15:38
14 Dec 08:36 15:37
15 Dec 08:37 15:38
16 Dec 08:38 15:38
17 Dec 08:39 15:38
18 Dec 08:39 15:38
19 Dec 08:40 15:38
20 Dec 08:41 15:39
21 Dec 08:41 15:39
22 Dec 08:42 15:40
23 Dec 08:42 15:40
24 Dec 08:43 15:41
25 Dec 08:43 15:41
26 Dec 08:43 15:42
27 Dec 08:44 15:43
28 Dec 08:44 15:44
29 Dec 08:44 15:45
30 Dec 08:44 15:46
31 Dec 08:44 15:47

Note: To install the gem use gem install RubySunrise.

Resources