Skip to content

Commit

Permalink
Merge branch 'release/1.0.29'
Browse files Browse the repository at this point in the history
* release/1.0.29:
  ### 1.0.29
  Add config option `temp_in` for f or c
  README update
  Version bump
  • Loading branch information
ttscoff committed Oct 1, 2023
2 parents 12d4803 + a57b2e8 commit e732b91
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### 1.0.29

2023-10-01 15:24

#### IMPROVED

- Config option `temp_in` can be set to `c` or `f` to control what scale temps are recorded in

### 1.0.28

2023-09-30 11:01
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
journal-cli (1.0.28)
journal-cli (1.0.29)
chronic (~> 0.10, >= 0.10.2)
tty-reader (~> 0.9, >= 0.9.0)
tty-which (~> 0.5, >= 0.5.0)
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ If a question type is set to `weather.forecast`, only the predicted condition, h

If the question type is `weather.current`, only the current condition and temperature will be recorded to the JSON, and a string containing "[TEMP] and [CONDITION]" (e.g. "64 and Sunny") will be recorded to Markdown/Day One for the question.

If the question type is `weather.moon`, only the moon phase will be output. Moon phase is also included in `weather.forecast` JSON and Markdown output.

### Journal Configuration

Edit the file at `~/.config/journal/journals.yaml` following this structure:
Expand Down Expand Up @@ -148,8 +150,9 @@ A question `type` can be one of:
- `text` or `string` will request a single-line string, submitted on return
- `multiline` for multiline strings (opens a readline editor, use ctrl-d to save)
- `weather` will just insert current weather data with no prompt
* `weather.forecast` will insert just the forecast
* `weather.current` will insert just the current temperature and condition
* `weather.forecast` will insert just the forecast (using weather history for backdated entries)
* `weather.current` will insert just the current temperature and condition (using weather history for backdated entries)
* `weather.moon` will insert the current moon phase for the entry date
- `number` or `float` will request numeric input, stored as a float (decimal)
- `integer` will convert numeric input to the nearest integer
- `date` will request a natural language date which will be parsed into a date object
Expand Down
2 changes: 1 addition & 1 deletion lib/journal-cli/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def ask(condition)
when /^(text|string|line)/i
read_line
when /^(weather|forecast)/i
Weather.new(Journal.config['weather_api'], Journal.config['zip'])
Weather.new(Journal.config['weather_api'], Journal.config['zip'], Journal.config['temp_in'])
when /^multi/i
read_lines
when /^(date|time)/i
Expand Down
2 changes: 1 addition & 1 deletion lib/journal-cli/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Journal
VERSION = '1.0.28'
VERSION = '1.0.29'
end
26 changes: 14 additions & 12 deletions lib/journal-cli/weather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Journal
class Weather
attr_reader :data

def initialize(api, zip)
def initialize(api, zip, temp_in)
Journal.date.localtime
if Journal.date.strftime('%Y-%m-%d') == Time.now.strftime('%Y-%m-%d')
res = `curl -SsL 'http://api.weatherapi.com/v1/forecast.json?key=#{api}&q=#{zip}&aqi=no'`
Expand All @@ -18,15 +18,17 @@ def initialize(api, zip)

raise StandardError, 'mising forecast' unless data['forecast']

temp_key = temp_in =~ /^c/ ? 'temp_c' : 'temp_f'

if Journal.date.strftime('%Y-%m-%d') == Time.now.strftime('%Y-%m-%d')
raise StandardError, 'missing conditions' unless data['current']

curr_temp = data['current']['temp_f']
curr_temp = data['current'][temp_key]
curr_condition = data['current']['condition']['text']
else
time = Journal.date.strftime('%Y-%m-%d %H:00')
hour = data['forecast']['forecastday'][0]['hour'].filter { |h| h['time'].to_s =~ /#{time}/ }.first
curr_temp = hour['temp_f']
curr_temp = hour[temp_key]
curr_condition = hour['condition']['text']
end

Expand All @@ -35,19 +37,19 @@ def initialize(api, zip)
moon_phase = forecast['astro']['moon_phase']

day = forecast['date']
high = forecast['day']['maxtemp_f']
low = forecast['day']['mintemp_f']
high = temp_in =~ /^c/ ? forecast['day']['maxtemp_c'] : forecast['day']['maxtemp_f']
low = temp_in =~ /^c/ ? forecast['day']['mintemp_c'] : forecast['day']['mintemp_f']
condition = forecast['day']['condition']['text']

hours = forecast['hour']
temps = [
{ temp: hours[8]['temp_f'], condition: hours[8]['condition']['text'] },
{ temp: hours[10]['temp_f'], condition: hours[10]['condition']['text'] },
{ temp: hours[12]['temp_f'], condition: hours[12]['condition']['text'] },
{ temp: hours[14]['temp_f'], condition: hours[14]['condition']['text'] },
{ temp: hours[16]['temp_f'], condition: hours[16]['condition']['text'] },
{ temp: hours[18]['temp_f'], condition: hours[18]['condition']['text'] },
{ temp: hours[19]['temp_f'], condition: hours[20]['condition']['text'] }
{ temp: hours[8][temp_key], condition: hours[8]['condition']['text'] },
{ temp: hours[10][temp_key], condition: hours[10]['condition']['text'] },
{ temp: hours[12][temp_key], condition: hours[12]['condition']['text'] },
{ temp: hours[14][temp_key], condition: hours[14]['condition']['text'] },
{ temp: hours[16][temp_key], condition: hours[16]['condition']['text'] },
{ temp: hours[18][temp_key], condition: hours[18]['condition']['text'] },
{ temp: hours[19][temp_key], condition: hours[20]['condition']['text'] }
]

@data = {
Expand Down
7 changes: 5 additions & 2 deletions src/_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ If a question type is set to `weather.forecast`, only the predicted condition, h

If the question type is `weather.current`, only the current condition and temperature will be recorded to the JSON, and a string containing "[TEMP] and [CONDITION]" (e.g. "64 and Sunny") will be recorded to Markdown/Day One for the question.

If the question type is `weather.moon`, only the moon phase will be output. Moon phase is also included in `weather.forecast` JSON and Markdown output.

### Journal Configuration

Edit the file at `~/.config/journal/journals.yaml` following this structure:
Expand Down Expand Up @@ -151,8 +153,9 @@ A question `type` can be one of:
- `text` or `string` will request a single-line string, submitted on return
- `multiline` for multiline strings (opens a readline editor, use ctrl-d to save)
- `weather` will just insert current weather data with no prompt
* `weather.forecast` will insert just the forecast
* `weather.current` will insert just the current temperature and condition
* `weather.forecast` will insert just the forecast (using weather history for backdated entries)
* `weather.current` will insert just the current temperature and condition (using weather history for backdated entries)
* `weather.moon` will insert the current moon phase for the entry date
- `number` or `float` will request numeric input, stored as a float (decimal)
- `integer` will convert numeric input to the nearest integer
- `date` will request a natural language date which will be parsed into a date object
Expand Down

0 comments on commit e732b91

Please sign in to comment.