From 44415c1c62f43a6c005496a50bdc6d0be72ca601 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Thu, 16 Jul 2020 18:15:17 -0400 Subject: [PATCH] Update dependencies --- shard.yml | 4 ++-- src/instances.cr | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/shard.yml b/shard.yml index 3d3734e..a5e8fd8 100644 --- a/shard.yml +++ b/shard.yml @@ -11,8 +11,8 @@ targets: dependencies: kemal: github: kemalcr/kemal - version: ~> 0.26.1 + branch: master -crystal: 0.34.0 +crystal: 0.35.1 license: AGPLv3 diff --git a/src/instances.cr b/src/instances.cr index d3d1a61..6f21c46 100644 --- a/src/instances.cr +++ b/src/instances.cr @@ -42,13 +42,11 @@ spawn do monitors += response["psp"]["monitors"].as_a page += 1 - if response["psp"]["perPage"].as_i * page > response["psp"]["totalMonitors"].as_i - break - end + break if response["psp"]["perPage"].as_i * page > response["psp"]["totalMonitors"].as_i rescue ex error_message = response.try &.as?(String).try &.["errorStats"]? error_message ||= ex.message - puts "Exception pulling monitors: #{error_message}" + puts "Error pulling monitors: #{error_message}" break end end @@ -56,6 +54,8 @@ spawn do body = HTTP::Client.get(URI.parse("https://raw.githubusercontent.com/wiki/omarroth/invidious/Invidious-Instances.md")).body headers = HTTP::Headers.new + instances = {} of String => Instance + body = body.split("### Blocked:")[0] body.scan(/\[(?[^ \]]+)\]\((?[^\)]+)\)( .(?[\x{1f100}-\x{1f1ff}]{2}))?/mx).each do |md| region = md["region"]?.try { |region| region.codepoints.map { |codepoint| (codepoint - 0x1f1a5).chr }.join("") } @@ -80,9 +80,12 @@ spawn do end monitor = monitors.try &.select { |monitor| monitor["name"].try &.as_s == host }[0]? - INSTANCES[host] = {flag: flag, region: region, stats: stats, type: type, uri: uri.to_s, monitor: monitor || INSTANCES[host]?.try &.[:monitor]?} + instances[host] = {flag: flag, region: region, stats: stats, type: type, uri: uri.to_s, monitor: monitor || instances[host]?.try &.[:monitor]?} end + INSTANCES.clear + INSTANCES.merge! instances + sleep 5.minutes Fiber.yield end