Created
February 16, 2010 11:25
-
-
Save gunn/305466 to your computer and use it in GitHub Desktop.
Radiant wiki spam cleaner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mechanize' | |
def process_links links_block | |
url_regex = /http:\/\/[^"\/\s]+/ | |
agent = Mechanize.new | |
clean_links = [] | |
possible_spam = [] | |
links_block.split("\n").each do |line| | |
begin | |
next unless url = url_regex.match(line) | |
links_to_radiant = agent.get("#{url}/admin/login").links_with(:href => "http://radiantcms.org") | |
suspect = links_to_radiant.size < 1 | |
puts "No links to radiant found at #{url}/admin/login" if suspect | |
rescue Exception => e | |
puts "Error for #{url} - #{e}" | |
# probably a 404 | |
suspect = true | |
end | |
if suspect | |
possible_spam << line.gsub!(/\s*\* (\*\S)?/, "* *spam(auto)? ") | |
else | |
clean_links << line | |
end | |
end | |
puts "\n\n" | |
puts "Clean Links:" | |
puts clean_links | |
puts "\n\n" | |
puts "Possible Spam:" | |
puts possible_spam | |
end | |
links_block = %q{ | |
* "Edmund Haselwanter":http://edmund.haselwanter.com on "edmund.haselwanter.com":http://edmund.haselwanter.com, "apart-elisabeth.miemingerplateau.at":http://apart-elisabeth.miemingerplateau.at, "miemingerplateau.at":http://www.miemingerplateau.at, "ecoSyn365":http://www.ecosyn365.com/,"The Cakemaker":http://www.the-cakemaker.at | |
* "Elastique":http://elastique.com.au & "Otilas":http://otilas.com.au on "Beehive App":http://beehiveapp.com | |
* Elevated Rails on "elevatedrails.com":http://www.elevatedrails.com | |
* Elliot on "Telephone Answering Services":http://www.telephoneansweringservice.org.uk | |
* Emule on "inchirieri masini":http://www.rentngo.ro | |
* "Empire: Total War Heaven":http://etw.heavengames.com/ on "etw.heavengames.com":http://etw.heavengames.com | |
* Erik Mallinson on "mallinson.us":http://mallinson.us, "coacalina.org":http://coacalina.org, and "malliliprints.com":http://malliliprints.com | |
* Erik van Oosten on "theatergroepzout.nl":http://www.theatergroepzout.nl, and "milo.grons.nl":http://milo.grons.nl | |
* "Essence of the tree":http://www.essenceofthetree.com Nursery site designed by Will Emerson of "Livelihood Technology":http://www.livelihoodtech.com | |
* Expex China on "expexchina.com":http://www.expexchina.com | |
* "Fab:IT":http://www.fab-it.dk/ on "VPSForce":http://vpsforce.eu/ | |
* "Farmers Market":http://www.farmersmarket.is | |
} | |
process_links links_block |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment