~singpolyma/jmp-pay

ref: 85b356f73d42fa21d224ffdc9880c8cb6f8721b1 jmp-pay/bin/active_tels_on_catapult -rwxr-xr-x 1.1 KiB
85b356f7Stephen Paul Weber Show what tels are paid-up but not in dashboard 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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