Chatty: Replace usernames by Twitch IDs
This commit is contained in:
parent
61f6cf281b
commit
4aa51045eb
4 changed files with 28 additions and 16 deletions
|
@ -7,6 +7,7 @@ class Config
|
||||||
property db : String = "./db.sqlite3"
|
property db : String = "./db.sqlite3"
|
||||||
property redisUrl : String = "127.0.0.1:6379"
|
property redisUrl : String = "127.0.0.1:6379"
|
||||||
property log_level : LogLevel = LogLevel::Debug
|
property log_level : LogLevel = LogLevel::Debug
|
||||||
|
property key_expiration_time : Int32 = 60
|
||||||
|
|
||||||
def self.load
|
def self.load
|
||||||
config_file = "./config.yml"
|
config_file = "./config.yml"
|
||||||
|
|
|
@ -9,20 +9,31 @@ module Providers::Chatty
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
private def postprocessing(res) : Nil
|
private def postprocessing(res) : JSON::Any
|
||||||
|
users = 0
|
||||||
|
|
||||||
|
# Counts the chatty supporters
|
||||||
|
res.as_a.each do |item|
|
||||||
|
next if item["id"] != "chatty"
|
||||||
|
users += item["usernames"].size
|
||||||
|
end
|
||||||
|
|
||||||
|
wg = WaitGroup.new(users)
|
||||||
|
|
||||||
res.as_a.each_with_index do |item, index|
|
res.as_a.each_with_index do |item, index|
|
||||||
item["id"].as_a if item["id"] != "chatty"
|
next if item["id"] != "chatty"
|
||||||
puts item
|
|
||||||
item["usernames"].as_a.each_with_index do |username, index|
|
item["usernames"].as_a.each_with_index do |username, index|
|
||||||
item["usernames"].as_a.size.times do
|
spawn do
|
||||||
spawn do
|
id = JSON::Any.new(Utils::GQL.new.get_user_id(username.to_s))
|
||||||
id = JSON::Any.new(Utils::GQL.new.get_user_id(username.to_s))
|
item["usernames"].as_a[index] = id
|
||||||
puts "username: #{username}, id: #{id}"
|
ensure
|
||||||
item["usernames"].as_a[index] = id
|
wg.done
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
pp res
|
# Waits for all the fibers to complete before returning res
|
||||||
|
wg.wait
|
||||||
|
return res
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,8 +16,7 @@ module Providers
|
||||||
spawn { info[1].send(Providers::BTTV.get_badges) }
|
spawn { info[1].send(Providers::BTTV.get_badges) }
|
||||||
spawn { info[2].send(Providers::FFZ.get_badges) }
|
spawn { info[2].send(Providers::FFZ.get_badges) }
|
||||||
spawn { info[3].send(Providers::DankChat.get_badges) }
|
spawn { info[3].send(Providers::DankChat.get_badges) }
|
||||||
Providers::Chatty.get_badges
|
spawn { info[4].send(Providers::Chatty.get_badges) }
|
||||||
# spawn { info[4].send(Providers::Chatty.get_badges) }
|
|
||||||
# spawn { info[5].send(Providers::SevenTV.get_badges) }
|
# spawn { info[5].send(Providers::SevenTV.get_badges) }
|
||||||
# items = {chatterino: info[0].receive, bttv: info.receive, ffz: ffz.receive, dankchat: dankchat.receive, chatty: chatty.receive}
|
# items = {chatterino: info[0].receive, bttv: info.receive, ffz: ffz.receive, dankchat: dankchat.receive, chatty: chatty.receive}
|
||||||
items = {
|
items = {
|
||||||
|
@ -25,7 +24,7 @@ module Providers
|
||||||
bttv: info[1].receive,
|
bttv: info[1].receive,
|
||||||
ffz: info[2].receive,
|
ffz: info[2].receive,
|
||||||
dankchat: info[3].receive,
|
dankchat: info[3].receive,
|
||||||
# chatty: info[4].receive,
|
chatty: info[4].receive,
|
||||||
# seventv: info[5].receive,
|
# seventv: info[5].receive,
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
|
|
|
@ -17,6 +17,7 @@ Kemal.config.app_name = "vanity-tester-backend"
|
||||||
SQL = DB.open("sqlite3://#{CONFIG.db}")
|
SQL = DB.open("sqlite3://#{CONFIG.db}")
|
||||||
REDIS_DB = Redis::Client.new(URI.parse("redis://#{CONFIG.redisUrl}"))
|
REDIS_DB = Redis::Client.new(URI.parse("redis://#{CONFIG.redisUrl}"))
|
||||||
LOGGER = LogHandler.new(STDOUT, CONFIG.log_level)
|
LOGGER = LogHandler.new(STDOUT, CONFIG.log_level)
|
||||||
|
REDIS_PREFIX = "vanity-tester-backend"
|
||||||
|
|
||||||
Utils.create_db
|
Utils.create_db
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ get "/badges" do |env|
|
||||||
next data
|
next data
|
||||||
end
|
end
|
||||||
data = Handlers.parse_badges(env)
|
data = Handlers.parse_badges(env)
|
||||||
Utils::Redis.save("badges", data, 300)
|
Utils::Redis.save("badges", data, CONFIG.key_expiration_time)
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ get "/7tv/badges" do |env|
|
||||||
next data
|
next data
|
||||||
end
|
end
|
||||||
data = Handlers.parse_7tv_badges(env)
|
data = Handlers.parse_7tv_badges(env)
|
||||||
Utils::Redis.save("7tvbadges", data, 300)
|
Utils::Redis.save("7tvbadges", data, CONFIG.key_expiration_time)
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ get "/7tv/paints" do |env|
|
||||||
next data
|
next data
|
||||||
end
|
end
|
||||||
data = Handlers.parse_7tv_paints(env)
|
data = Handlers.parse_7tv_paints(env)
|
||||||
Utils::Redis.save("7tvpaints", data, 300)
|
Utils::Redis.save("7tvpaints", data, CONFIG.key_expiration_time)
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue