Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require './config/environment'
- class Parser
- USER_LOGIN = ENV['LOGIN']
- USER_PASSWORD = ENV['PASSWORD']
- URL_LOGIN = ENV['URL_LOGIN']
- URL_SUPPORT_LIST = ENV['URL_SUPPORT_LIST']
- URL_POST_REQUEST = ENV['URL_POST_REQUEST']
- def auth(agent)
- page = agent.get(URL_LOGIN)
- login_form = page.form(action: "/login/login")
- login_form.field(name: "login").value = USER_LOGIN
- login_form.field(name: "password").value = USER_PASSWORD
- agent.submit(login_form)
- end
- def parse(page)
- support_list = Array.new
- text = page.at('/html/body/div[2]/div/div[3]/div/div[2]/div/div/div[2]/div[1]/div[3]/div/article/div/div[2]/div/div[1]/div').text
- server = nil
- text.delete("\t").split(/\n/, -1).each do |str|
- if str.include? "Revolution"
- server = 101
- elsif str.include? "Legacy"
- server = 103
- elsif str.include? "Underground"
- server = 104
- end
- if str.match(/(\w+_\w+)[ ]*\//)
- nick = str.match(/(\w+_\w+)[ ]*\//)[1]
- support_list << {name: nick, server: server}
- end
- end
- support_list
- end
- def send_post_request(support_list)
- if support_list.length > 5
- json_list = support_list.to_json
- uri = URI(URL_POST_REQUEST)
- print(json_list)
- headers = { 'Content-Type': 'application/json' }
- response = Net::HTTP.post(uri, json_list, headers)
- end
- end
- def execute
- agent = Mechanize.new
- auth(agent)
- page = agent.get(URL_SUPPORT_LIST)
- support_list = parse(page)
- send_post_request(support_list)
- end
- end
- Parser.new.execute
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement