~singpolyma/jmp-pay

85b356f73d42fa21d224ffdc9880c8cb6f8721b1 — Stephen Paul Weber 2 years ago 4d64029
Show what tels are paid-up but not in dashboard
2 files changed, 52 insertions(+), 0 deletions(-)

M Gemfile
A bin/active_tels_on_catapult
M Gemfile => Gemfile +1 -0
@@ 9,6 9,7 @@ gem "money-open-exchange-rates"
gem "pg"
gem "redis"
gem "roda"
gem "ruby-bandwidth-iris"
gem "sentry-ruby"
gem "slim"


A bin/active_tels_on_catapult => bin/active_tels_on_catapult +51 -0
@@ 0,0 1,51 @@
#!/usr/bin/ruby
# frozen_string_literal: true

require "dhall"
require "net/http"
require "pg"
require "redis"
require "ruby-bandwidth-iris"

require_relative "../lib/blather_notify"

CONFIG = Dhall.load(ARGV[0]).sync

BandwidthIris::Client.global_options = {
	account_id: CONFIG[:creds][:account],
	username: CONFIG[:creds][:username],
	password: CONFIG[:creds][:password]
}

REDIS = Redis.new
DB = PG.connect(dbname: "jmp")
DB.type_map_for_results = PG::BasicTypeMapForResults.new(DB)
DB.type_map_for_queries = PG::BasicTypeMapForQueries.new(DB)

def get_location(tel)
	BandwidthIris::Tn.get(tel).get_sip_peers[:name]
rescue BandwidthIris::Errors::GenericError
	nil
end

DB.exec(
	<<~SQL
		select customer_id
		from customer_plans
		where expires_at > localtimestamp
	SQL
).each do |row|
	cid = row["customer_id"]
	next if REDIS.exists?("catapult_cred-customer_#{cid}@jmp.chat")
	jid = REDIS.get("jmp_customer_jid-#{cid}")
	tel = REDIS.lindex("catapult_cred-#{jid}", 3)
	location = get_location(tel)
	if location.nil?
		# in catapult
		puts tel
	elsif location == "location1"
		# in dashboard, using v1
	else
		raise "Unexpected location #{location}"
	end
end