Skip to content

Commit

Permalink
test&bin
Browse files Browse the repository at this point in the history
  • Loading branch information
although2013 committed May 27, 2015
1 parent ef7e378 commit b7ebd12
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs << 'test'
end

desc "Run tests"
task :default => :test
13 changes: 13 additions & 0 deletions bin/getscore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env ruby

require 'getscore'


print "输入登录信息->\n"
print "学号: "
xh = gets.chomp
print "密码:"
mm = gets.chomp

me = CheckOne.new(xh, mm)
me.get_score.parse_html
9 changes: 5 additions & 4 deletions getscore.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Gem::Specification.new do |s|
s.name = 'getscore'
s.version = '0.0.0'
s.version = '0.0.2'
s.date = '2015-05-26'
s.summary = "Hola!"
s.summary = "Get Score!"
s.description = "A gem for get URP score"
s.authors = ["Ge Hao"]
s.email = 'althoughghgh@gmail.com'
s.files = ["lib/getscore.rb",
"lib/getscore/check_one.rb",
s.files = ["lib/getscore.rb",
"lib/getscore/check_one.rb",
"lib/getscore/get_class.rb"]
s.homepage = 'http://although2013.com'
s.license = 'MIT'
s.executables << 'getscore'
end
4 changes: 3 additions & 1 deletion lib/getscore/check_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def check_internet
puts "#{host}"
end
end
puts "wait threads"
threads.each(&:join)
end

def get_session
puts "force get session"
puts "force get session, |this method should not run|"
request = Net::HTTP::Post.new('/loginAction.do')
request.set_form_data({ 'zjh' => @username, 'mm' => @passwd })
response = @http.request(request)
Expand Down Expand Up @@ -90,3 +91,4 @@ def parse_html
end

end

15 changes: 10 additions & 5 deletions lib/getscore/get_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def get_whole_page
request = Net::HTTP::Post.new('/reportFiles/zhjwcx/syxqcjxx/zhjwcx_syxqcjxx_jtcjcx.jsp')
request['Cookie'] = @session
request.set_form_data("xsh"=>"05", "zxjxjhh"=>"2014-2015-2-1", "bjh"=>"")
respones = @http.request(request)
body = respones.body.force_encoding('gbk').encode('utf-8')
response = @http.request(request)
body = response.body.force_encoding('gbk').encode('utf-8')
end


Expand All @@ -17,8 +17,13 @@ def download_text(html)
html.match /saveAsText.*\s?\{\s+.*src.*"(.*)";$/

request = Net::HTTP::Get.new(URI($1.to_s))
respones = @http.request(request)
body = respones.body
File.open("html_file.tmp", "w") { |file| file.write(body) }
@http.request(request) do |response|
File.open("html_file.tmp", "w") do |file|
response.read_body do |segment|
file.write(segment)
end
end
end

end
end
14 changes: 14 additions & 0 deletions test/test_getscore.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'minitest/autorun'
require 'getscore'

class GetscoreTest < Minitest::Test

def test_all
me = CheckOne.new("2012021712", "1")
me.get_score.parse_html

page = me.get_whole_page
me.download_text(page)
end

end

0 comments on commit b7ebd12

Please sign in to comment.