git-fit 0.7.9 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/git-fit.rb +44 -42
- data/lib/git_fit/cli/export.rb +8 -6
- data/lib/git_fit/cli/geo_cli.rb +10 -8
- data/lib/git_fit/cli/gh_cli.rb +24 -22
- data/lib/git_fit/cli/import_cli.rb +40 -38
- data/lib/git_fit/cli/install_cli.rb +10 -8
- data/lib/git_fit/cli/sync.rb +9 -7
- data/lib/git_fit/cli.rb +29 -27
- data/lib/git_fit/config.rb +42 -28
- data/lib/git_fit/config_template.rb +2 -0
- data/lib/git_fit/db/activity.rb +2 -0
- data/lib/git_fit/db/cli.rb +11 -9
- data/lib/git_fit/db/connection.rb +8 -6
- data/lib/git_fit/db/rebuild.rb +5 -3
- data/lib/git_fit/export/defaults.rb +14 -12
- data/lib/git_fit/export/json.rb +5 -3
- data/lib/git_fit/export.rb +4 -2
- data/lib/git_fit/fit/decoder.rb +9 -7
- data/lib/git_fit/fit.rb +3 -1
- data/lib/git_fit/geo/amap_client.rb +15 -13
- data/lib/git_fit/geo/coord_transform.rb +2 -0
- data/lib/git_fit/geo/division_detector.rb +31 -26
- data/lib/git_fit/geo/nominatim_client.rb +14 -12
- data/lib/git_fit/geo/polyline.rb +4 -2
- data/lib/git_fit/geo/reverse_geocode.rb +11 -9
- data/lib/git_fit/geo.rb +8 -6
- data/lib/git_fit/import/apple_health.rb +84 -82
- data/lib/git_fit/import/local_file.rb +45 -42
- data/lib/git_fit/import.rb +4 -2
- data/lib/git_fit/install/actions.rb +15 -13
- data/lib/git_fit/parser/base.rb +12 -10
- data/lib/git_fit/parser/fit.rb +11 -9
- data/lib/git_fit/parser/gpx.rb +17 -15
- data/lib/git_fit/parser/tcx.rb +22 -20
- data/lib/git_fit/parser.rb +6 -4
- data/lib/git_fit/privacy/polyline_filter.rb +6 -4
- data/lib/git_fit/source/base.rb +25 -23
- data/lib/git_fit/source/tally.rb +9 -7
- data/lib/git_fit/source.rb +4 -2
- data/lib/git_fit/sport_mapper.rb +23 -21
- data/lib/git_fit/sync/base.rb +29 -27
- data/lib/git_fit/sync/garmin.rb +5 -3
- data/lib/git_fit/sync/garmin_base.rb +145 -143
- data/lib/git_fit/sync/garmin_base_di.rb +42 -40
- data/lib/git_fit/sync/garmin_cn.rb +8 -6
- data/lib/git_fit/sync/igpsport.rb +43 -41
- data/lib/git_fit/sync/keep.rb +98 -96
- data/lib/git_fit/sync/lorem.rb +31 -29
- data/lib/git_fit/sync/runner.rb +14 -11
- data/lib/git_fit/sync/strava.rb +61 -52
- data/lib/git_fit/sync/xingzhe.rb +52 -50
- data/lib/git_fit/sync/xoss.rb +68 -66
- data/lib/git_fit/timezone/resolver.rb +5 -3
- data/lib/git_fit/util/tally.rb +10 -8
- data/lib/git_fit/util.rb +2 -0
- data/lib/git_fit/version.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fec2ac95bb7dbd444aef685e129221b5344838937449de995d6c1ef05315ed8a
|
|
4
|
+
data.tar.gz: 7cee0bbccf7ce0495f37f83bfa8e0c2b98f0c36009f43dea353b89d142d0ca00
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 452fedbcc1e11299532c15c57df405fdf49d95e75a4185727aaab4684d6a1cf69630210b22b9c6f67e1d907083139375fd5de87f45da4b55e2ccd882a6378b0e
|
|
7
|
+
data.tar.gz: 3c0d2f2fce0b7d79f2c47b859754a8ef54b2df09577fe191939b516488b285527db46b59e10b55109fcc4550bf217c445271898dfe4ad95e12d2ad17f2ba41c7
|
data/lib/git-fit.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
require 'fileutils'
|
|
4
6
|
|
|
5
7
|
module GitFit
|
|
6
8
|
SPORT_CATEGORIES = %w[run ride hike walk swim ski workout other].freeze
|
|
@@ -30,7 +32,7 @@ module GitFit
|
|
|
30
32
|
summary_polyline: a[:summary_polyline],
|
|
31
33
|
average_heartrate: a[:average_heartrate],
|
|
32
34
|
average_speed: a[:average_speed],
|
|
33
|
-
elevation_gain: a[:elevation_gain]
|
|
35
|
+
elevation_gain: a[:elevation_gain],
|
|
34
36
|
}
|
|
35
37
|
end
|
|
36
38
|
|
|
@@ -39,45 +41,45 @@ module GitFit
|
|
|
39
41
|
hours = seconds / 3600
|
|
40
42
|
minutes = (seconds % 3600) / 60
|
|
41
43
|
secs = seconds % 60
|
|
42
|
-
format(
|
|
44
|
+
format('%d:%02d:%02d', hours, minutes, secs)
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
end
|
|
46
48
|
|
|
47
|
-
require_relative
|
|
48
|
-
require_relative
|
|
49
|
-
require_relative
|
|
50
|
-
require_relative
|
|
51
|
-
require_relative
|
|
52
|
-
require_relative
|
|
53
|
-
require_relative
|
|
54
|
-
require_relative
|
|
55
|
-
require_relative
|
|
56
|
-
require_relative
|
|
57
|
-
require_relative
|
|
58
|
-
require_relative
|
|
59
|
-
require_relative
|
|
60
|
-
require_relative
|
|
61
|
-
require_relative
|
|
62
|
-
require_relative
|
|
63
|
-
require_relative
|
|
64
|
-
require_relative
|
|
65
|
-
require_relative
|
|
66
|
-
require_relative
|
|
67
|
-
require_relative
|
|
68
|
-
require_relative
|
|
69
|
-
require_relative
|
|
70
|
-
require_relative
|
|
71
|
-
require_relative
|
|
72
|
-
require_relative
|
|
73
|
-
require_relative
|
|
74
|
-
require_relative
|
|
75
|
-
require_relative
|
|
76
|
-
require_relative
|
|
77
|
-
require_relative
|
|
78
|
-
require_relative
|
|
79
|
-
require_relative
|
|
80
|
-
require_relative
|
|
81
|
-
require_relative
|
|
82
|
-
require_relative
|
|
83
|
-
require_relative
|
|
49
|
+
require_relative 'git_fit/version'
|
|
50
|
+
require_relative 'git_fit/config'
|
|
51
|
+
require_relative 'git_fit/config_template'
|
|
52
|
+
require_relative 'git_fit/sport_mapper'
|
|
53
|
+
require_relative 'git_fit/geo'
|
|
54
|
+
require_relative 'git_fit/fit'
|
|
55
|
+
require_relative 'git_fit/parser'
|
|
56
|
+
require_relative 'git_fit/source'
|
|
57
|
+
require_relative 'git_fit/timezone/resolver'
|
|
58
|
+
require_relative 'git_fit/privacy/polyline_filter'
|
|
59
|
+
require_relative 'git_fit/import'
|
|
60
|
+
require_relative 'git_fit/sync/base'
|
|
61
|
+
require_relative 'git_fit/util'
|
|
62
|
+
require_relative 'git_fit/sync/lorem'
|
|
63
|
+
require_relative 'git_fit/sync/garmin_base'
|
|
64
|
+
require_relative 'git_fit/sync/garmin_base_di'
|
|
65
|
+
require_relative 'git_fit/sync/garmin'
|
|
66
|
+
require_relative 'git_fit/sync/garmin_cn'
|
|
67
|
+
require_relative 'git_fit/sync/strava'
|
|
68
|
+
require_relative 'git_fit/sync/keep'
|
|
69
|
+
require_relative 'git_fit/sync/igpsport'
|
|
70
|
+
require_relative 'git_fit/sync/xoss'
|
|
71
|
+
require_relative 'git_fit/sync/xingzhe'
|
|
72
|
+
require_relative 'git_fit/sync/runner'
|
|
73
|
+
require_relative 'git_fit/cli/sync'
|
|
74
|
+
require_relative 'git_fit/db/rebuild'
|
|
75
|
+
require_relative 'git_fit/db/connection'
|
|
76
|
+
require_relative 'git_fit/db/activity'
|
|
77
|
+
require_relative 'git_fit/export'
|
|
78
|
+
require_relative 'git_fit/db/cli'
|
|
79
|
+
require_relative 'git_fit/install/actions'
|
|
80
|
+
require_relative 'git_fit/cli/install_cli'
|
|
81
|
+
require_relative 'git_fit/cli/gh_cli'
|
|
82
|
+
require_relative 'git_fit/cli/export'
|
|
83
|
+
require_relative 'git_fit/cli/import_cli'
|
|
84
|
+
require_relative 'git_fit/cli/geo_cli'
|
|
85
|
+
require_relative 'git_fit/cli'
|
data/lib/git_fit/cli/export.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
2
4
|
|
|
3
5
|
module GitFit
|
|
4
6
|
class ExportCLI < Thor
|
|
5
|
-
desc
|
|
6
|
-
option :output, type: :string, aliases:
|
|
7
|
-
option :activity, type: :array, desc:
|
|
7
|
+
desc 'json', 'Export activities to JSON'
|
|
8
|
+
option :output, type: :string, aliases: '-o', desc: 'Output path'
|
|
9
|
+
option :activity, type: :array, desc: 'Filter by sport type', aliases: '--act'
|
|
8
10
|
no_commands do
|
|
9
11
|
def git_fit_config
|
|
10
12
|
@git_fit_config ||= GitFit::Config.new(options[:config])
|
|
@@ -16,11 +18,11 @@ module GitFit
|
|
|
16
18
|
conn = GitFit::DB::Connection.new(config.db_path)
|
|
17
19
|
conn.migrate!
|
|
18
20
|
db = conn.db
|
|
19
|
-
path = options[:output] || config.export_config.dig(
|
|
21
|
+
path = options[:output] || config.export_config.dig('json', 'path') || 'site/activities.json'
|
|
20
22
|
filter = options[:activity]&.map(&:strip)&.map(&:downcase)
|
|
21
23
|
count = Export::JSON.new(db: db, output: path, activity_filter: filter).call
|
|
22
24
|
say_status :done, "Exported #{count} activities to #{path}", :green
|
|
23
|
-
rescue => e
|
|
25
|
+
rescue StandardError => e
|
|
24
26
|
say_status :error, "JSON export failed: #{e.message}", :red
|
|
25
27
|
end
|
|
26
28
|
end
|
data/lib/git_fit/cli/geo_cli.rb
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
2
4
|
|
|
3
5
|
module GitFit
|
|
4
6
|
class GeoCLI < Thor
|
|
5
|
-
desc
|
|
6
|
-
option :limit, type: :numeric, aliases:
|
|
7
|
-
option :batch, type: :numeric, aliases:
|
|
8
|
-
option :strategy, type: :string, aliases:
|
|
9
|
-
option :time, type: :numeric, aliases:
|
|
7
|
+
desc 'detect', 'Detect administrative divisions for activities with GPS data'
|
|
8
|
+
option :limit, type: :numeric, aliases: '-l', desc: 'Max activities to process'
|
|
9
|
+
option :batch, type: :numeric, aliases: '-b', desc: 'Batch size', default: 20
|
|
10
|
+
option :strategy, type: :string, aliases: '-s', desc: 'Strategy: proportional|start_end', default: 'proportional'
|
|
11
|
+
option :time, type: :numeric, aliases: '-t', desc: 'Time budget in seconds'
|
|
10
12
|
option :"dry-run", type: :boolean, desc: "Don't write to DB"
|
|
11
13
|
def detect
|
|
12
14
|
config = GitFit::Config.new
|
|
13
15
|
conn = GitFit::DB::Connection.new(config.db_path)
|
|
14
16
|
conn.migrate!
|
|
15
17
|
db = conn.db
|
|
16
|
-
amap_key = ENV[
|
|
18
|
+
amap_key = ENV['AMAP_API_KEY'] || config.sync_config('amap')['api_key']
|
|
17
19
|
detector = GitFit::Geo::DivisionDetector.new(
|
|
18
20
|
db: db,
|
|
19
21
|
amap_key: amap_key,
|
|
@@ -24,7 +26,7 @@ module GitFit
|
|
|
24
26
|
dry_run: options[:"dry-run"],
|
|
25
27
|
)
|
|
26
28
|
detector.run
|
|
27
|
-
rescue => e
|
|
29
|
+
rescue StandardError => e
|
|
28
30
|
say_status :error, "Geo detection failed: #{e.message}", :red
|
|
29
31
|
end
|
|
30
32
|
end
|
data/lib/git_fit/cli/gh_cli.rb
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'open3'
|
|
3
5
|
|
|
4
6
|
module GitFit
|
|
5
7
|
module GhHelpers
|
|
6
8
|
def detect_repo(url = nil)
|
|
7
9
|
url ||= `git remote get-url origin`.chomp
|
|
8
|
-
url.sub(%r{.*github\.com[:/]},
|
|
10
|
+
url.sub(%r{.*github\.com[:/]}, '').sub(/\.git$/, '')
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def gh(*args)
|
|
12
14
|
repo = options[:repo] || detect_repo
|
|
13
|
-
out, err, st = Open3.capture3(
|
|
15
|
+
out, err, st = Open3.capture3('gh', *args.map(&:to_s), '-R', repo)
|
|
14
16
|
raise "gh: #{err.strip}" unless st.success?
|
|
15
17
|
out
|
|
16
18
|
end
|
|
@@ -19,50 +21,50 @@ module GitFit
|
|
|
19
21
|
class GhSecretCLI < Thor
|
|
20
22
|
include GhHelpers
|
|
21
23
|
|
|
22
|
-
class_option :repo, type: :string, desc:
|
|
24
|
+
class_option :repo, type: :string, desc: 'GitHub repo (owner/repo)'
|
|
23
25
|
|
|
24
|
-
desc
|
|
26
|
+
desc 'list', 'List secrets'
|
|
25
27
|
def list
|
|
26
|
-
puts gh(
|
|
28
|
+
puts gh('secret', 'list')
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
desc
|
|
31
|
+
desc 'set KEY', 'Set a secret (reads value from stdin or prompt)'
|
|
30
32
|
def set(key)
|
|
31
|
-
puts gh(
|
|
33
|
+
puts gh('secret', 'set', key)
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
desc
|
|
36
|
+
desc 'delete KEY', 'Delete a secret'
|
|
35
37
|
def delete(key)
|
|
36
|
-
puts gh(
|
|
38
|
+
puts gh('secret', 'delete', key)
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
class GhConfigCLI < Thor
|
|
41
43
|
include GhHelpers
|
|
42
44
|
|
|
43
|
-
class_option :repo, type: :string, desc:
|
|
45
|
+
class_option :repo, type: :string, desc: 'GitHub repo (owner/repo)'
|
|
44
46
|
|
|
45
|
-
desc
|
|
47
|
+
desc 'list', 'List variables'
|
|
46
48
|
def list
|
|
47
|
-
puts gh(
|
|
49
|
+
puts gh('variable', 'list')
|
|
48
50
|
end
|
|
49
51
|
|
|
50
|
-
desc
|
|
52
|
+
desc 'set KEY VALUE', 'Set a variable'
|
|
51
53
|
def set(key, value)
|
|
52
|
-
puts gh(
|
|
54
|
+
puts gh('variable', 'set', key, '--body', value)
|
|
53
55
|
end
|
|
54
56
|
|
|
55
|
-
desc
|
|
57
|
+
desc 'get KEY', 'Get a variable value'
|
|
56
58
|
def get(key)
|
|
57
|
-
puts gh(
|
|
59
|
+
puts gh('variable', 'get', key)
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
class GhCLI < Thor
|
|
62
|
-
desc
|
|
63
|
-
subcommand
|
|
64
|
+
desc 'secret SUBCOMMAND', 'Manage GitHub Secrets'
|
|
65
|
+
subcommand 'secret', GhSecretCLI
|
|
64
66
|
|
|
65
|
-
desc
|
|
66
|
-
subcommand
|
|
67
|
+
desc 'config SUBCOMMAND', 'Manage GitHub Variables'
|
|
68
|
+
subcommand 'config', GhConfigCLI
|
|
67
69
|
end
|
|
68
70
|
end
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
2
4
|
|
|
3
5
|
module GitFit
|
|
4
6
|
class ImportCLI < Thor
|
|
5
7
|
FILE_SOURCES = %w[gpx fit tcx].freeze
|
|
6
8
|
|
|
7
|
-
desc
|
|
8
|
-
option :source, type: :string, aliases:
|
|
9
|
-
desc:
|
|
10
|
-
option :activity, type: :array, desc:
|
|
11
|
-
option :sport, type: :string, desc:
|
|
9
|
+
desc 'all', 'Import from all sources (gpx, fit, tcx)'
|
|
10
|
+
option :source, type: :string, aliases: '-s',
|
|
11
|
+
desc: 'Import source(s) — comma-separated (default: gpx,fit,tcx)'
|
|
12
|
+
option :activity, type: :array, desc: 'Filter by sport type', aliases: '--act'
|
|
13
|
+
option :sport, type: :string, desc: 'Override sport_category for GPX files'
|
|
12
14
|
def all
|
|
13
|
-
sources = (options[:source] ||
|
|
15
|
+
sources = (options[:source] || 'gpx,fit,tcx').split(',').map(&:strip).map(&:downcase)
|
|
14
16
|
unknown = sources.reject { |s| FILE_SOURCES.include?(s) }
|
|
15
17
|
unless unknown.empty?
|
|
16
18
|
say_status :error, "Unknown source(s): #{unknown.join(', ')}. Supported: gpx, fit, tcx", :red
|
|
@@ -22,7 +24,7 @@ module GitFit
|
|
|
22
24
|
conn.migrate!
|
|
23
25
|
db = conn.db
|
|
24
26
|
filter = options[:activity]&.map(&:strip)&.map(&:downcase)
|
|
25
|
-
time_budget = config.dig(
|
|
27
|
+
time_budget = config.dig('sync', 'time_budget')
|
|
26
28
|
sport_override = options[:sport]
|
|
27
29
|
|
|
28
30
|
total = 0
|
|
@@ -37,12 +39,12 @@ module GitFit
|
|
|
37
39
|
count = adapter.call
|
|
38
40
|
say_status :done, "#{source}: #{count} activities", :green
|
|
39
41
|
total += count
|
|
40
|
-
rescue => e
|
|
42
|
+
rescue StandardError => e
|
|
41
43
|
say_status :error, "#{source}: #{e.message}", :red
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
if total.zero?
|
|
45
|
-
say_status :warn,
|
|
47
|
+
say_status :warn, '0 activities imported', :yellow
|
|
46
48
|
else
|
|
47
49
|
say_status :done, "Total: #{total} activities", :green
|
|
48
50
|
end
|
|
@@ -50,113 +52,113 @@ module GitFit
|
|
|
50
52
|
|
|
51
53
|
default_command :all
|
|
52
54
|
|
|
53
|
-
desc
|
|
54
|
-
option :activity, type: :array, desc:
|
|
55
|
-
option :sport, type: :string, desc:
|
|
55
|
+
desc 'gpx', 'Import GPX files from data/import/gpx/'
|
|
56
|
+
option :activity, type: :array, desc: 'Filter by sport type', aliases: '--act'
|
|
57
|
+
option :sport, type: :string, desc: 'Override sport_category for GPX files'
|
|
56
58
|
def gpx
|
|
57
59
|
config = GitFit::Config.new
|
|
58
60
|
conn = GitFit::DB::Connection.new(config.db_path)
|
|
59
61
|
conn.migrate!
|
|
60
62
|
db = conn.db
|
|
61
63
|
filter = options[:activity]&.map(&:strip)&.map(&:downcase)
|
|
62
|
-
time_budget = config.dig(
|
|
64
|
+
time_budget = config.dig('sync', 'time_budget')
|
|
63
65
|
sport_override = options[:sport]
|
|
64
66
|
|
|
65
|
-
say_status :import,
|
|
67
|
+
say_status :import, 'gpx', :green
|
|
66
68
|
adapter = GitFit::Import::LocalFile.new(
|
|
67
69
|
config: {}, db:, activity_filter: filter,
|
|
68
70
|
time_budget: time_budget,
|
|
69
|
-
sources: [
|
|
71
|
+
sources: ['gpx'],
|
|
70
72
|
sport_override: sport_override
|
|
71
73
|
)
|
|
72
74
|
|
|
73
75
|
begin
|
|
74
76
|
count = adapter.call
|
|
75
77
|
if count == 0
|
|
76
|
-
say_status :warn,
|
|
78
|
+
say_status :warn, 'gpx: 0 activities (already imported or none found)', :yellow
|
|
77
79
|
else
|
|
78
80
|
say_status :done, "gpx: #{count} activities", :green
|
|
79
81
|
end
|
|
80
82
|
count
|
|
81
|
-
rescue => e
|
|
83
|
+
rescue StandardError => e
|
|
82
84
|
say_status :error, "gpx: #{e.message}", :red
|
|
83
85
|
0
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
88
|
|
|
87
|
-
desc
|
|
88
|
-
option :activity, type: :array, desc:
|
|
89
|
+
desc 'tcx', 'Import TCX files from data/import/tcx/'
|
|
90
|
+
option :activity, type: :array, desc: 'Filter by sport type', aliases: '--act'
|
|
89
91
|
def tcx
|
|
90
92
|
config = GitFit::Config.new
|
|
91
93
|
conn = GitFit::DB::Connection.new(config.db_path)
|
|
92
94
|
conn.migrate!
|
|
93
95
|
db = conn.db
|
|
94
96
|
filter = options[:activity]&.map(&:strip)&.map(&:downcase)
|
|
95
|
-
time_budget = config.dig(
|
|
97
|
+
time_budget = config.dig('sync', 'time_budget')
|
|
96
98
|
|
|
97
|
-
say_status :import,
|
|
99
|
+
say_status :import, 'tcx', :green
|
|
98
100
|
adapter = GitFit::Import::LocalFile.new(
|
|
99
101
|
config: {}, db:, activity_filter: filter,
|
|
100
102
|
time_budget: time_budget,
|
|
101
|
-
sources: [
|
|
103
|
+
sources: ['tcx']
|
|
102
104
|
)
|
|
103
105
|
|
|
104
106
|
begin
|
|
105
107
|
count = adapter.call
|
|
106
108
|
if count == 0
|
|
107
|
-
say_status :warn,
|
|
109
|
+
say_status :warn, 'tcx: 0 activities (already imported or none found)', :yellow
|
|
108
110
|
else
|
|
109
111
|
say_status :done, "tcx: #{count} activities", :green
|
|
110
112
|
end
|
|
111
113
|
count
|
|
112
|
-
rescue => e
|
|
114
|
+
rescue StandardError => e
|
|
113
115
|
say_status :error, "tcx: #{e.message}", :red
|
|
114
116
|
0
|
|
115
117
|
end
|
|
116
118
|
end
|
|
117
119
|
|
|
118
|
-
desc
|
|
119
|
-
option :activity, type: :array, desc:
|
|
120
|
+
desc 'fit', 'Import FIT files from data/import/fit/'
|
|
121
|
+
option :activity, type: :array, desc: 'Filter by sport type', aliases: '--act'
|
|
120
122
|
def fit
|
|
121
123
|
config = GitFit::Config.new
|
|
122
124
|
conn = GitFit::DB::Connection.new(config.db_path)
|
|
123
125
|
conn.migrate!
|
|
124
126
|
db = conn.db
|
|
125
127
|
filter = options[:activity]&.map(&:strip)&.map(&:downcase)
|
|
126
|
-
time_budget = config.dig(
|
|
128
|
+
time_budget = config.dig('sync', 'time_budget')
|
|
127
129
|
|
|
128
|
-
say_status :import,
|
|
130
|
+
say_status :import, 'fit', :green
|
|
129
131
|
adapter = GitFit::Import::LocalFile.new(
|
|
130
132
|
config: {}, db:, activity_filter: filter,
|
|
131
133
|
time_budget: time_budget,
|
|
132
|
-
sources: [
|
|
134
|
+
sources: ['fit']
|
|
133
135
|
)
|
|
134
136
|
|
|
135
137
|
begin
|
|
136
138
|
count = adapter.call
|
|
137
139
|
if count == 0
|
|
138
|
-
say_status :warn,
|
|
140
|
+
say_status :warn, 'fit: 0 activities (already imported or none found)', :yellow
|
|
139
141
|
else
|
|
140
142
|
say_status :done, "fit: #{count} activities", :green
|
|
141
143
|
end
|
|
142
144
|
count
|
|
143
|
-
rescue => e
|
|
145
|
+
rescue StandardError => e
|
|
144
146
|
say_status :error, "fit: #{e.message}", :red
|
|
145
147
|
0
|
|
146
148
|
end
|
|
147
149
|
end
|
|
148
150
|
|
|
149
|
-
desc
|
|
150
|
-
option :activity, type: :array, desc:
|
|
151
|
+
desc 'apple_health', 'Import from Apple Health export.zip'
|
|
152
|
+
option :activity, type: :array, desc: 'Filter by sport type', aliases: '--act'
|
|
151
153
|
def apple_health
|
|
152
154
|
config = GitFit::Config.new
|
|
153
155
|
conn = GitFit::DB::Connection.new(config.db_path)
|
|
154
156
|
conn.migrate!
|
|
155
157
|
db = conn.db
|
|
156
158
|
filter = options[:activity]&.map(&:strip)&.map(&:downcase)
|
|
157
|
-
time_budget = config.dig(
|
|
159
|
+
time_budget = config.dig('sync', 'time_budget')
|
|
158
160
|
|
|
159
|
-
say_status :import,
|
|
161
|
+
say_status :import, 'apple_health', :green
|
|
160
162
|
adapter = GitFit::Import::AppleHealth.new(
|
|
161
163
|
config: {}, db:, activity_filter: filter,
|
|
162
164
|
time_budget: time_budget
|
|
@@ -165,12 +167,12 @@ module GitFit
|
|
|
165
167
|
begin
|
|
166
168
|
count = adapter.call
|
|
167
169
|
if count == 0
|
|
168
|
-
say_status :warn,
|
|
170
|
+
say_status :warn, 'apple_health: 0 activities (already imported or none found)', :yellow
|
|
169
171
|
else
|
|
170
172
|
say_status :done, "apple_health: #{count} activities", :green
|
|
171
173
|
end
|
|
172
174
|
count
|
|
173
|
-
rescue => e
|
|
175
|
+
rescue StandardError => e
|
|
174
176
|
say_status :error, "apple_health: #{e.message}", :red
|
|
175
177
|
0
|
|
176
178
|
end
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'yaml'
|
|
4
6
|
|
|
5
7
|
module GitFit
|
|
6
8
|
class InstallCLI < Thor
|
|
7
|
-
desc
|
|
8
|
-
option :check, type: :boolean, desc:
|
|
9
|
-
option :"dry-run", type: :boolean, desc:
|
|
9
|
+
desc 'actions [family]', 'Install GitHub Actions (default: all families)'
|
|
10
|
+
option :check, type: :boolean, desc: 'Check on-disk files against templates, exit non-zero on mismatch'
|
|
11
|
+
option :"dry-run", type: :boolean, desc: 'Render templates and print without writing'
|
|
10
12
|
def actions(family = nil)
|
|
11
13
|
check = options[:check]
|
|
12
14
|
dry_run = options[:"dry-run"]
|
|
13
15
|
|
|
14
16
|
if check && dry_run
|
|
15
|
-
say
|
|
16
|
-
raise Thor::Error,
|
|
17
|
+
say 'Error: --check and --dry-run are mutually exclusive', :red
|
|
18
|
+
raise Thor::Error, 'Cannot use --check and --dry-run together'
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
results = GitFit::Install::Actions.install(family, check: check, dry_run: dry_run)
|
data/lib/git_fit/cli/sync.rb
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module GitFit
|
|
2
4
|
module Cli
|
|
3
5
|
module Sync
|
|
4
6
|
def sync
|
|
5
7
|
db = connect_db
|
|
6
8
|
source = options[:source]
|
|
7
|
-
filter = options[:activity]&.flat_map { |v| v.split(
|
|
9
|
+
filter = options[:activity]&.flat_map { |v| v.split(',') }&.map(&:strip)&.map(&:downcase)
|
|
8
10
|
privacy = GitFit::Privacy::PolylineFilter.new(config: git_fit_config.privacy_config)
|
|
9
11
|
|
|
10
12
|
sources = if source
|
|
11
13
|
[source]
|
|
12
14
|
else
|
|
13
|
-
configured = (git_fit_config[
|
|
15
|
+
configured = (git_fit_config['sync'] || {}).select { |_k, v| v.is_a?(Hash) }.keys
|
|
14
16
|
builtin = GitFit::Sync::Base.adapters
|
|
15
17
|
.map { |c| c.config_key }
|
|
16
|
-
if ENV[
|
|
18
|
+
if ENV['GIT_FIT_ENVIRONMENT'] == 'testing'
|
|
17
19
|
builtin += GitFit::Sync::Base.test_adapters
|
|
18
20
|
.map { |c| c.config_key }
|
|
19
21
|
end
|
|
@@ -26,12 +28,12 @@ module GitFit
|
|
|
26
28
|
config: git_fit_config,
|
|
27
29
|
activity_filter: filter,
|
|
28
30
|
privacy: privacy,
|
|
29
|
-
num_workers: git_fit_config.dig(
|
|
30
|
-
time_budget: git_fit_config.dig(
|
|
31
|
-
total_timeout: git_fit_config.dig(
|
|
31
|
+
num_workers: git_fit_config.dig('sync', 'workers') || 3,
|
|
32
|
+
time_budget: git_fit_config.dig('sync', 'time_budget'),
|
|
33
|
+
total_timeout: git_fit_config.dig('sync', 'total_timeout')
|
|
32
34
|
)
|
|
33
35
|
runner.run
|
|
34
|
-
rescue => e
|
|
36
|
+
rescue StandardError => e
|
|
35
37
|
say_status :error, e.message, :red
|
|
36
38
|
end
|
|
37
39
|
end
|