PDA

View Full Version : Ruby- Red rep automation.



Haldrik
02-15-2016, 12:38 AM
EDIT: ITS FINISHED. DRAFIX COMPLETED THE AUTOMATION.

SEE THIS THREAD. http://forum.gsplayers.com/showthread.php?100750-AUTOMATE-RED-REP-NAMES

(THE BELOW THREAD IS GOOD IF YOU WANT TO SEE HOW I SCRAPED THE NAMES FROM THE WEBSITE)


See this post: http://forum.gsplayers.com/showthread.php?36834-Respond-to-Reputation-Comments&p=1836921#post1836921

Basically, you can view the user ID of anyone who red reps you. You can then plug their user id as noted above. Or do a ctrl-f on the below paste-bin.

List of user Ids/Usernames.

http://pastebin.com/zLqgHCZz

-------------------
Code. Idea is to automate it further.


http://pastebin.com/zLqgHCZz



## scrape a website for user names




require "open-uri" # Use this library to do network requests

the_url = "http://forum.gsplayers.com/memberlist.php?&order=asc&sort=username"
name_user_id = Hash.new(0)
current_page = 0
last_page = 339

while current_page.to_i != last_page.to_i
begin
open(the_url) do |content|
content.each_line { |line|
name_user_id[$1] = $2 if line =~ /<td class="alt1 username"><a href="member\.php\?(\d+)-(.+?)"/
}
if current_page.to_i != last_page.to_i
current_page = current_page.to_i
current_page += 1
the_url = "http://forum.gsplayers.com/memberlist.php?page=#{current_page}&order=asc&sort=username"
end
end
rescue OpenURI::HTTPError
name_user_id.each {|key, value|
name_clean = value.gsub /&amp.+/, ""
puts "Id: #{key}"
puts "Username: #{name_clean}"
puts "-"
}
end
end

File.open("output.txt", 'w') { |file|
name_user_id.each {|key, value|
name_clean = value.gsub /&amp.+/, ""
file.write("Id: #{key}, Username: #{name_clean}\n")
}
}