Skip to content

Commit

Permalink
Fix ameba spec
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Apr 18, 2024
1 parent 0661f25 commit 2c1e1b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 0 additions & 2 deletions spec/myip_spec.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "./spec_helper"

describe Myip do
# TODO: Write tests

it "works" do
false.should eq(false)
end
Expand Down
6 changes: 3 additions & 3 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ USAGE
end

myip = Myip.new
myip.get_ip_from_ip138
myip.get_ip_from_ib_sb
myip.get_ip_from_ip111
myip.ip_from_ip138
myip.ip_from_ib_sb
myip.ip_from_ip111
myip.process

at_exit do
Expand Down
12 changes: 6 additions & 6 deletions src/myip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Myip
property chan_send_count : Int32 = 0
property ip111_chan_send_count : Int32 = 0

def get_ip_from_ib_sb
def ip_from_ib_sb
self.chan_send_count = chan_send_count() + 1

spawn do
Expand All @@ -26,7 +26,7 @@ class Myip
end
end

def get_ip_from_ip111
def ip_from_ip111
# 注意: ip111.cn 仅支持 http, 不支持 https:
ip111_url = "http://www.ip111.cn"

Expand Down Expand Up @@ -59,12 +59,12 @@ class Myip
end
end

def get_ip_from_ip138
def ip_from_ip138
self.chan_send_count = chan_send_count + 1

spawn do
url = "https://www.ip138.com"
doc, code = from_url(url, follow: true)
doc, _code = from_url(url, follow: true)
ip138_url = doc.css("iframe").first.attribute_by("src")
headers = HTTP::Headers{"Origin" => "https://ip.skk.moe"}

Expand All @@ -73,7 +73,7 @@ class Myip
if code == 502
myip = doc.css("body p span.F").first.tag_text[/IP:\s*([0-9.]+)/, 1]
url = "https://www.ip138.com/iplookup.php?ip=#{myip}"
doc, code = from_url(url, headers: headers)
doc, _code = from_url(url, headers: headers)

output = String.build do |io|
doc.css("div.table-box>table>tbody tr").each { |x| io << x.tag_text }
Expand Down Expand Up @@ -102,7 +102,7 @@ class Myip
spawn do
details_ip_url = "https://www.ipshudi.com/#{ip}.htm"

doc, code = from_url(details_ip_url)
doc, _code = from_url(details_ip_url)

output = String.build do |io|
doc.css("div.ft>table>tbody>tr>td").each { |x| io << x.tag_text }
Expand Down

0 comments on commit 2c1e1b5

Please sign in to comment.