Python LogoAsk any website owner about their top ten list of difficulties faced when running their website and almost all of them will include getting traffic to their site when new content becomes available. For website owners using website software such as WordPress, it is actually pretty easy to notify other websites when you have added a new article or updated an existing article. For those website owners, they can rely on the built-in utility called the “pinger” which you can read about here. However, for those of you that aren’t using tools such as WordPress (or for those of you who just want to learn how to notify other sites about updates to your site using your own code), I have decided to write a short article that will show you how to do this very thing using Python. To make it even better, I will do this using only the modules that come included with the base install of Python. So, let’s begin.

The first thing you will need for notifying other websites about updates to your own site is a list of the websites you want to notify, duh. đŸ™‚ Since I have already mentioned WordPress in this article, I think I’ll use the list that they provide on their website.

http://rpc.pingomatic.com
http://rpc.twingly.com
http://api.feedster.com/ping
http://api.moreover.com/RPC2
http://api.moreover.com/ping
http://www.blogdigger.com/RPC2
http://www.blogshares.com/rpc.php
http://www.blogsnow.com/ping
http://www.blogstreet.com/xrbin/xmlrpc.cgi
http://bulkfeeds.net/rpc
http://www.newsisfree.com/xmlrpctest.php
http://ping.blo.gs/
http://ping.feedburner.com
http://ping.syndic8.com/xmlrpc.php
http://ping.weblogalot.com/rpc.php
http://rpc.blogrolling.com/pinger/
http://rpc.technorati.com/rpc/ping
http://rpc.weblogs.com/RPC2
http://www.feedsubmitter.com
http://blo.gs/ping.php
http://www.pingerati.net
http://www.pingmyblog.com
http://geourl.org/ping
http://ipings.com
http://www.weblogalot.com/ping

Copy those URLs and save them into a file called “pinger_server_list.txt”. The name of the file doesn’t really matter just as long as you put each URL on a separate line of its own.
Next, you’ll need to create a new Python file. I called mine “pinger.py”, but you can name yours’ whatever you want.

Copy the following code into your Python script and save it.

import xmlrpclib

blog_name = 'Prodigy Productions, LLC'
blog_url = 'http://www.prodigyproductionsllc.com'
pinger_server_list_filename = 'pinger_server_list.txt'

#ping_urls = ['http://rpc.pingomatic.com', 'http://rpc.weblogs.com/RPC2']
with open(pinger_server_list_filename) as f:
    ping_urls = f.readlines()

for ping_url in ping_urls:
    print 'Pinging:', ping_url.strip()
    s = xmlrpclib.Server(ping_url.strip())
    reply = s.weblogUpdates.ping(blog_name, blog_url)
    print 'Reply:', reply, '\n'

In the code, you will need to change the fields for “blog_name” and “blog_url” to match the name and URL of your own blog. If you saved your list of URLs to a file with a name other than “pinger_server_list.txt”, you’ll also need to change the “pinger_server_list_filename” variable to match the name of your file.

I should also point out that you can use this same script for notifying other websites about changes to your website even if your website is not a blog.

As you can see in the code, this script starts out by reading in the list of URLs from your file and storing them in an array called “ping_urls”. If you do not want to read your list of URLs from a file, I have also provided some sample code that shows how to hardcode your URLs in an array of the same name. Just remove the leading “#” sign and the following 2 lines after the array instantiation.

Once you have your URLs stored in an array, the next piece of code in this script will iterate thru each of those URLs and will submit the name of your website and its URL to each of the URLs in your list. It does that by using the “weblogUpdates.ping” method provided by the “xmlrpclib.Server” class. The “xmlrpclib” module comes preloaded with Python when you install it. Therefore you don’t have to worry about installing any 3rd party libraries. This also makes the code perfect for running on different operating systems and computers. Pretty cool, huh?

After the script has submitted your site to a URL in your list, the server at the other end will return a JSON response which you can use to identify whether or not the ping was successful. For this example, I simply print out the entire response to the screen so that you can see what the fields are in the JSON response in case you want to do something further with the replies. The standard response will include “message” and “flerror”. Some servers will also include other fields, but I’m not going to get into all of those at this time.

That’s it! You now have everything you need for notifying other websites about updates to your own website. Any time you want to let others know that you have made changes to your website, simply run this Python script and it will take care of the rest for you. Just make sure you use a good list of XML RPC based servers. You can also find ping servers that will notify other lists of websites for you which will generate even more traffic to your website when you ask them to by running this script.

P.S. If you do not want to run this script from your console, you can always incorporate this code into an HTTP server (which you can learn about by clicking here). If you do that, you can set your script to run on your server using a different port than the one in use by your web app and can call it from your web browser whenever you want to run your pinger code.

Thank you for your interest in my site. If you find the information provided on this site useful, please consider making a donation to help continue development!

PayPal will open in a new tab.
$2.00
$5.00
Other

Related Posts

Leave a Reply