1
0
mirror of https://github.com/elisspace/FxLifeSheet.git synced 2026-08-29 15:44:00 +00:00

Add weight importer for Renpho

This commit is contained in:
Felix Krause
2022-04-21 20:33:28 +02:00
parent bee593da81
commit 9b55d7b31d

View File

@@ -0,0 +1,49 @@
require_relative '../importer'
require 'net/http'
require 'csv'
module Importers
class Weight < Importer
def import
weight_file.each do |current_date, values|
weight = values[:weight]
next unless weight > 0
insert_row_for_date(
key: "weight",
value: weight,
date: current_date,
type: "number",
question: "Current weight",
source: "weight",
import_id: import_id
)
current_date += 1
end
end
private
def import_id
@_import_id ||= SecureRandom.hex
end
def weight_file
@weight_file ||= CSV.read(File.join("importers", "weight", "renpho.csv"), headers: true).collect do |row|
parsed = row["Date"].match(/(\d\d\/\d\d\/\d\d\d\d)/)[1]
[
Date.strptime(parsed, '%m/%d/%Y'),
{
weight: row["Weight"].to_f
}
]
end.to_h
end
end
end
if __FILE__ == $0
Importers::Weight.new.import
end