journal-cli 1.0.26 → 1.0.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4984b6fe36150316fca655279b8bff861e006da77028b78327132e711798b7e3
4
- data.tar.gz: 43d4b24bd3f27d92bf781496fad939037cf8258d34bd835b1d148010ad184806
3
+ metadata.gz: 125cde5de56092483eb664d0b34ee250fdd8d0f47681f2bcd9e47866b9493cf1
4
+ data.tar.gz: 99eb86fa5648dbca59ca0337e30324e6fbbab01ff4daeeca5e4421647e273fc6
5
5
  SHA512:
6
- metadata.gz: 8cbbd48551378617d527c661a7a022735766f4f09dee40ab903c1687d23967a69e250007d5ac2a0b0e4cb3d6209d2edcb43f18ef7fbe205a0abf2cb0c2a93c04
7
- data.tar.gz: daec6aadef725293d2e4db82f69187a3230b18c31a71e8a45de28a00b47fc961f9f1020d6930cda8c374e16401cddd5fa3abcd12f8343879c645d86d476652d0
6
+ metadata.gz: c61d83d83236c28af72ada995ed0a06d579f9e1d7b8c9c6d6a694ffc6dadcf19c64f1eabd4ac3073adee75224ff4020980d5b9c1064801297dd6183673858b74
7
+ data.tar.gz: 816870f6d23c9648c699c8cdc02c802182486044798a3c1ad36981ccfee4c18d266ca29571ab625679bb1d3f737fc8f17d163f84a5e15c1d3142267192367e79
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 1.0.28
2
+
3
+ 2023-09-30 11:01
4
+
5
+ #### IMPROVED
6
+
7
+ - If creating an entry for a past date, get the historical weather for that date
8
+ - Add weather.moon type for getting moon phase, and include moon_phase in general weather data
9
+
10
+ ### 1.0.27
11
+
12
+ 2023-09-23 08:03
13
+
14
+ #### FIXED
15
+
16
+ - Time comparisons for past entries failing when using a past date for entry
17
+
1
18
  ### 1.0.26
2
19
 
3
20
  2023-09-20 19:18
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- journal-cli (1.0.25)
4
+ journal-cli (1.0.28)
5
5
  chronic (~> 0.10, >= 0.10.2)
6
6
  tty-reader (~> 0.9, >= 0.9.0)
7
7
  tty-which (~> 0.5, >= 0.5.0)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ::Array
4
+ def shortest
5
+ inject { |memo, word| memo.length < word.length ? memo : word }
6
+ end
7
+
8
+ def longest
9
+ inject { |memo, word| memo.length > word.length ? memo : word }
10
+ end
11
+ end
@@ -136,11 +136,13 @@ module Journal
136
136
  return if data.nil? || !data.key?(key) || data[key].nil?
137
137
 
138
138
  case type
139
- when /^(weather|forecast)/
139
+ when /^(weather|forecast|moon)/
140
140
  header prompt
141
141
  @output << case type
142
142
  when /current$/
143
143
  data[key].current
144
+ when /moon$/
145
+ "Moon phase: #{data[key].moon}"
144
146
  else
145
147
  data[key].to_markdown
146
148
  end
@@ -174,6 +176,8 @@ module Journal
174
176
  v.current
175
177
  when /forecast$/
176
178
  data[k] = v.forecast
179
+ when /moon(_?phase)?$/
180
+ data[k] = v.moon
177
181
  else
178
182
  data[k] = v.to_s
179
183
  end
@@ -258,17 +262,23 @@ module Journal
258
262
  v.each do |key, value|
259
263
  result = case value.class.to_s
260
264
  when /Weather/
261
- if key =~ /current$/
262
- {
263
- 'temp' => value.data[:temp],
264
- 'condition' => value.data[:current_condition]
265
- }
266
- else
267
- {
268
- 'high' => value.data[:high],
269
- 'low' => value.data[:low],
270
- 'condition' => value.data[:condition]
271
- }
265
+ case key
266
+ when /current$/
267
+ {
268
+ 'temp' => value.data[:temp],
269
+ 'condition' => value.data[:current_condition]
270
+ }
271
+ when /moon(_?phase)?$/
272
+ {
273
+ 'phase' => value.data[:moon_phase]
274
+ }
275
+ else
276
+ {
277
+ 'high' => value.data[:high],
278
+ 'low' => value.data[:low],
279
+ 'condition' => value.data[:condition],
280
+ 'moon_phase' => value.data[:moon_phase]
281
+ }
272
282
  end
273
283
  else
274
284
  value
@@ -10,17 +10,20 @@ class ::String
10
10
  now = Journal.date
11
11
  m = condition.match(time_rx)
12
12
  time = Chronic.parse(m['time'])
13
+ now.localtime
14
+ time.localtime
15
+ time_of_day = Time.parse("#{now.strftime('%Y-%m-%d')} #{time.strftime('%H:%M')}")
13
16
  Journal.notify("{br}Invalid time string in question (#{m['time']})", exit_code: 4) unless time
14
17
 
15
18
  case m['comp']
16
19
  when /^<=$/
17
- now <= time
20
+ now <= time_of_day
18
21
  when /^(<|bef)/i
19
- now < time
22
+ now < time_of_day
20
23
  when /^>=/
21
- now >= time
24
+ now >= time_of_day
22
25
  when /^(>|aft)/i
23
- now > time
26
+ now > time_of_day
24
27
  end
25
28
  # TODO: Other condition types
26
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Journal
4
- VERSION = '1.0.26'
4
+ VERSION = '1.0.28'
5
5
  end
@@ -5,20 +5,35 @@ module Journal
5
5
  attr_reader :data
6
6
 
7
7
  def initialize(api, zip)
8
- res = `curl -SsL 'http://api.weatherapi.com/v1/forecast.json?key=#{api}&q=#{zip}&aqi=no'`
8
+ Journal.date.localtime
9
+ if Journal.date.strftime('%Y-%m-%d') == Time.now.strftime('%Y-%m-%d')
10
+ res = `curl -SsL 'http://api.weatherapi.com/v1/forecast.json?key=#{api}&q=#{zip}&aqi=no'`
11
+ else
12
+ res = `curl -SsL 'http://api.weatherapi.com/v1/history.json?key=#{api}&q=#{zip}&aqi=no&dt=#{Journal.date.strftime('%Y-%m-%d')}'`
13
+ end
14
+
9
15
  data = JSON.parse(res)
10
16
 
11
17
  raise StandardError, 'invalid JSON response' if data.nil?
12
18
 
13
- raise StandardError, 'missing conditions' unless data['current']
19
+ raise StandardError, 'mising forecast' unless data['forecast']
14
20
 
15
- curr_temp = data['current']['temp_f']
16
- curr_condition = data['current']['condition']['text']
21
+ if Journal.date.strftime('%Y-%m-%d') == Time.now.strftime('%Y-%m-%d')
22
+ raise StandardError, 'missing conditions' unless data['current']
17
23
 
18
- raise StandardError, 'mising forecast' unless data['forecast']
24
+ curr_temp = data['current']['temp_f']
25
+ curr_condition = data['current']['condition']['text']
26
+ else
27
+ time = Journal.date.strftime('%Y-%m-%d %H:00')
28
+ hour = data['forecast']['forecastday'][0]['hour'].filter { |h| h['time'].to_s =~ /#{time}/ }.first
29
+ curr_temp = hour['temp_f']
30
+ curr_condition = hour['condition']['text']
31
+ end
19
32
 
20
33
  forecast = data['forecast']['forecastday'][0]
21
34
 
35
+ moon_phase = forecast['astro']['moon_phase']
36
+
22
37
  day = forecast['date']
23
38
  high = forecast['day']['maxtemp_f']
24
39
  low = forecast['day']['mintemp_f']
@@ -42,18 +57,24 @@ module Journal
42
57
  temp: curr_temp,
43
58
  condition: condition,
44
59
  current_condition: curr_condition,
45
- temps: temps
60
+ temps: temps,
61
+ moon_phase: moon_phase
46
62
  }
47
63
  end
48
64
 
49
65
  def to_data
50
66
  {
51
- high: high,
52
- low: low,
53
- condition: curr_condition
67
+ high: @data[:high],
68
+ low: @data[:low],
69
+ condition: @data[:current_condition],
70
+ moon_phase: @data[:moon_phase]
54
71
  }
55
72
  end
56
73
 
74
+ def moon
75
+ @data[:moon_phase]
76
+ end
77
+
57
78
  def current
58
79
  "#{@data[:temp]} and #{@data[:current_condition]}"
59
80
  end
@@ -70,7 +91,8 @@ module Journal
70
91
  output = []
71
92
 
72
93
  output << "Forecast for #{@data[:day]}: #{forecast} "
73
- output << "Currently: #{current}"
94
+ output << "Currently: #{current} "
95
+ output << "Moon Phase: #{moon} "
74
96
  output << ''
75
97
 
76
98
  # Hours
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: journal-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.26
4
+ version: 1.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-21 00:00:00.000000000 Z
11
+ date: 2023-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-which
@@ -232,6 +232,7 @@ files:
232
232
  - bin/journal
233
233
  - journal-cli.gemspec
234
234
  - lib/journal-cli.rb
235
+ - lib/journal-cli/array.rb
235
236
  - lib/journal-cli/checkin.rb
236
237
  - lib/journal-cli/color.rb
237
238
  - lib/journal-cli/data.rb