Created
August 18, 2008 17:31
-
-
Save PabloC/6037 to your computer and use it in GitHub Desktop.
Ping to Search Engines
This file contains hidden or 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
# Source: http://seventytwo.co.uk/posts/how-to-reach-enlightenment-and-get-your-site-indexed-by-search-engines | |
# Switch output on or off | |
OUTPUT = true | |
# Sitemap URL | |
SITEMAP_URL = 'http://www.example.com/sitemap.xml' | |
# Search engine pings configuration | |
pings_config = [ | |
{:name => 'Google', | |
:url => 'http://www.google.com/webmasters/sitemaps/ping?sitemap='}, | |
{:name => 'Yahoo!', | |
:url => 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap='}, | |
{:name => 'Ask.com', | |
:url => 'http://submissions.ask.com/ping?sitemap='}, | |
{:name => 'Microsoft Live Search', | |
:url => 'http://webmaster.live.com/ping.aspx?siteMap='}, | |
{:name => 'Moreover.com', | |
:url => 'http://api.moreover.com/ping?u='} | |
]; | |
# ................................................................. | |
require 'cgi' | |
require 'net/http' | |
class Ping | |
attr_accessor :pinged_count | |
def initialize(pings_config) | |
# Loop through sites to ping | |
@pinged_count = 0; | |
pings_config.each do |ping_config| | |
# Construct ping URL | |
ping_url = ping_config[:url] + CGI::escape(SITEMAP_URL); | |
# Execute HTTP request to ping URL | |
response = Net::HTTP.get_response(URI.parse(ping_url)) | |
# Check HTTP status code | |
result = true if response.code == '200' | |
# Increment the pinged_count if successfully pinged | |
@pinged_count += 1 if result | |
# Output ping result | |
puts "[#{result ? 'OK' : 'ERROR'}] #{ping_config[:name]}" if OUTPUT | |
end | |
end | |
end | |
# Count number of sites to ping | |
stat_pings_count = pings_config.size; | |
# Ping the sites | |
ping = Ping.new(pings_config) | |
# Output ping results summary | |
puts "Pinged #{ping.pinged_count} out of #{stat_pings_count} sites successfully" if OUTPUT | |
# exit 0 # Needed if script is run from the CLI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment