Sha256: a77a04735728aba81ce16e4a4984bd8900157a4f3ccc797b0f5e548db59eeffe

Contents?: true

Size: 774 Bytes

Versions: 1

Compression:

Stored size: 774 Bytes

Contents

require "lwqzx/version"
require 'nokogiri'

module Lwqzx
  def self.auth(login,passwd)
    lurl = "http://www.lwqzx.sdedu.net/kernel/net_school/active_app/login1.php"
    user = "login_user_m_=#{login}"
    psd = "login_password=#{passwd}"
    res = %x[curl #{lurl} -s -c /tmp/cookies -d #{user} -d #{psd} ]
    infos = %x[curl -s -b /tmp/cookies #{lurl}]
    content=infos.encode("UTF-8","GB2312")
    doc = Nokogiri::HTML(content)
    uname = doc.css("span.tt1 a:nth-child(1)").text
    return {} if uname == ""
    groups = doc.css("span.tt1 a:nth-child(5)")[0]["title"]
    %x[rm /tmp/cookies]
    groups=groups.gsub("[","").gsub("]","").split("@").compact.reject(&:empty?)
    return {login: login, name: uname, groups: groups}
  end 
end

Lwqzx.auth("dsfas","dsfasd")

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lwqzx-0.0.5 lib/lwqzx.rb