From d2bb428afc85c05d0e62efd12b53a685b2615c11 Mon Sep 17 00:00:00 2001 From: "intermittent.energy" Date: Tue, 24 Dec 2024 07:45:24 +0000 Subject: [PATCH] EiaBulk accept filter argument --- lib/eia_bulk.rb | 9 +++++---- scripts/stream-eia-eba.rb | 6 ------ 2 files changed, 5 insertions(+), 10 deletions(-) delete mode 100755 scripts/stream-eia-eba.rb diff --git a/lib/eia_bulk.rb b/lib/eia_bulk.rb index 7a1c03e..08a2cbc 100644 --- a/lib/eia_bulk.rb +++ b/lib/eia_bulk.rb @@ -8,7 +8,7 @@ def self.source_id end def self.cli(args) - unless args.length == 1 + if args.length < 1 $stderr.puts "#{$0}: " return end @@ -43,6 +43,7 @@ def process m = line.match(/"series_id":"(.*?)"/) next unless m @series = m[1] + next unless @series.include?(@filter) if @filter process_line(line) { |row| conn.put_copy_data(row) } end end @@ -79,7 +80,7 @@ class Generation < Base BULK_TABLE = "eia_bulk_generation" TARGET_MODEL = ::Generation - def initialize(args) + def initialize(*args) super ActiveRecord::Base.connection.create_enum :eia_bulk_production_type, %w[fossil_gas fossil_hard_coal fossil_oil hydro nuclear other solar wind unknown] ActiveRecord::Base.connection.create_table BULK_TABLE, id: false, temporary: true do |t| @@ -147,7 +148,7 @@ class Demand < Base BULK_TABLE = "eia_bulk_demand" TARGET_MODEL = Load - def initialize(args) + def initialize(*args) super ActiveRecord::Base.connection.create_table BULK_TABLE, id: false, temporary: true do |t| t.timestamptz :time, null: false @@ -200,7 +201,7 @@ class Interchange < Base BULK_TABLE = "eia_bulk_interchange" TARGET_MODEL = Transmission - def initialize(args) + def initialize(*args) super ActiveRecord::Base.connection.create_table BULK_TABLE, id: false, temporary: true do |t| t.timestamptz :time, null: false diff --git a/scripts/stream-eia-eba.rb b/scripts/stream-eia-eba.rb deleted file mode 100755 index f49ef70..0000000 --- a/scripts/stream-eia-eba.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby -# coding: utf-8 -require './lib/init' -require './lib/activerecord-connect' - -EiaBulk::EBA.cli(ARGV)