getscore 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/getscore +13 -0
- data/lib/getscore/check_one.rb +94 -0
- data/lib/getscore/get_class.rb +29 -0
- data/lib/getscore.rb +23 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: a95aefd61f3606b5da7574ae0397ffbbd2ac220d
|
|
4
|
+
data.tar.gz: f3c49a6728f803c102d4954975e1847d1d42f4f4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cb50915b9debc3f54a2fb561180dff18c5ce394890a49d03045d806114dd9a91697b3d344ffeae4462d36d3acdb3d270cf9d0faa8a216c04280a2acfffc6979b
|
|
7
|
+
data.tar.gz: 2d7467356f9c67883d8bcf42178f692e610b11288d5c1b61e3aef5b54d1b9b094346bc0609e431789a5b2a79e230ef2322dd53562557e2af723cb8aac929a0d1
|
data/bin/getscore
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#encoding = utf-8
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
require 'digest'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class String
|
|
8
|
+
#等宽字体中英文混合时占用的宽度
|
|
9
|
+
def ulen()
|
|
10
|
+
(self.bytesize + self.length) / 2
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CheckOne
|
|
16
|
+
attr_accessor :session
|
|
17
|
+
|
|
18
|
+
def initialize(username, passwd)
|
|
19
|
+
@username = username
|
|
20
|
+
@passwd = passwd
|
|
21
|
+
@port = 80
|
|
22
|
+
@session = nil
|
|
23
|
+
|
|
24
|
+
check_internet
|
|
25
|
+
@http = Net::HTTP.new(@host, @port)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def check_internet
|
|
29
|
+
hosts = ["60.219.165.24", "192.168.11.239"]
|
|
30
|
+
threads = []
|
|
31
|
+
hosts.each do |host|
|
|
32
|
+
threads << Thread.new do
|
|
33
|
+
uri = URI("http://#{host}/loginAction.do")
|
|
34
|
+
response = Net::HTTP.post_form(uri, 'zjh' => @username, 'mm' => @passwd)
|
|
35
|
+
return if "200" != response.code
|
|
36
|
+
threads.each { |thread| Thread.kill(thread) if thread != Thread.current }
|
|
37
|
+
@host = host
|
|
38
|
+
@session = response["set-cookie"]
|
|
39
|
+
puts "*#{@session}*"
|
|
40
|
+
puts "#{host}"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
puts "wait threads"
|
|
44
|
+
threads.each(&:join)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def get_session
|
|
48
|
+
puts "force get session, |this method should not run|"
|
|
49
|
+
request = Net::HTTP::Post.new('/loginAction.do')
|
|
50
|
+
request.set_form_data({ 'zjh' => @username, 'mm' => @passwd })
|
|
51
|
+
response = @http.request(request)
|
|
52
|
+
|
|
53
|
+
raise "can't get session" if !response.code == '200'
|
|
54
|
+
@session = response["set-cookie"]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def get_score
|
|
58
|
+
puts "get my score"
|
|
59
|
+
raise "get_session first OR no session" if @session == nil
|
|
60
|
+
request = Net::HTTP::Get.new('/bxqcjcxAction.do')
|
|
61
|
+
request['Cookie'] = @session
|
|
62
|
+
response = @http.request(request)
|
|
63
|
+
@body = response.body.force_encoding('gbk').encode('utf-8').gsub(/\s/,"")
|
|
64
|
+
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def different?
|
|
69
|
+
puts "diff?"
|
|
70
|
+
last = File.exist?("last_digest.tmp") ? File.read("last_digest.tmp") : nil
|
|
71
|
+
now = Digest::SHA2.hexdigest(@body)
|
|
72
|
+
|
|
73
|
+
if last == now
|
|
74
|
+
return false
|
|
75
|
+
else
|
|
76
|
+
puts "It's different now!"
|
|
77
|
+
File.open("last_digest.tmp", "w") { |file| file.print now }
|
|
78
|
+
return true
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def parse_html
|
|
83
|
+
puts "parse my score"
|
|
84
|
+
@body =~ /thead(.*)<\/TABLE/
|
|
85
|
+
arr = $1.scan(/>(.{0,15})<\/td/).map(&:first)
|
|
86
|
+
max_ulen = arr.map(&:ulen).max
|
|
87
|
+
puts "---------------------------------------------------"
|
|
88
|
+
arr.each_slice(7) do |row|
|
|
89
|
+
printf("%-9s %-4s %-s %s %-5s %-4s %-4s\n",row[0],row[1],row[2],(" "*(max_ulen - row[2].ulen)),row[4],row[5],row[6])
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#encoding = utf-8
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module GetClassTxt
|
|
5
|
+
def get_whole_page
|
|
6
|
+
puts "get faculty score"
|
|
7
|
+
request = Net::HTTP::Post.new('/reportFiles/zhjwcx/syxqcjxx/zhjwcx_syxqcjxx_jtcjcx.jsp')
|
|
8
|
+
request['Cookie'] = @session
|
|
9
|
+
request.set_form_data("xsh"=>"05", "zxjxjhh"=>"2014-2015-2-1", "bjh"=>"")
|
|
10
|
+
response = @http.request(request)
|
|
11
|
+
body = response.body.force_encoding('gbk').encode('utf-8')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def download_text(html)
|
|
16
|
+
puts "download_text"
|
|
17
|
+
html.match /saveAsText.*\s?\{\s+.*src.*"(.*)";$/
|
|
18
|
+
|
|
19
|
+
request = Net::HTTP::Get.new(URI($1.to_s))
|
|
20
|
+
@http.request(request) do |response|
|
|
21
|
+
File.open("html_file.tmp", "w") do |file|
|
|
22
|
+
response.read_body do |segment|
|
|
23
|
+
file.write(segment)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/getscore.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#encoding = utf-8
|
|
2
|
+
require 'getscore/get_class'
|
|
3
|
+
require 'getscore/check_one'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CheckOne
|
|
7
|
+
include GetClassTxt
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
#me = CheckOne.new("2012021712", "1")
|
|
12
|
+
#
|
|
13
|
+
#me.get_session
|
|
14
|
+
#
|
|
15
|
+
#me.get_score.parse_html
|
|
16
|
+
#
|
|
17
|
+
#if me.different?
|
|
18
|
+
# page = me.get_whole_page
|
|
19
|
+
# me.download_text(page)
|
|
20
|
+
#end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: getscore
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ge Hao
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A gem for get URP score
|
|
14
|
+
email: althoughghgh@gmail.com
|
|
15
|
+
executables:
|
|
16
|
+
- getscore
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- bin/getscore
|
|
21
|
+
- lib/getscore.rb
|
|
22
|
+
- lib/getscore/check_one.rb
|
|
23
|
+
- lib/getscore/get_class.rb
|
|
24
|
+
homepage: http://although2013.com
|
|
25
|
+
licenses:
|
|
26
|
+
- MIT
|
|
27
|
+
metadata: {}
|
|
28
|
+
post_install_message:
|
|
29
|
+
rdoc_options: []
|
|
30
|
+
require_paths:
|
|
31
|
+
- lib
|
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
requirements: []
|
|
43
|
+
rubyforge_project:
|
|
44
|
+
rubygems_version: 2.4.6
|
|
45
|
+
signing_key:
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: Get Score!
|
|
48
|
+
test_files: []
|