<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My blog &#187; wordpress</title>
	<atom:link href="http://www.drak0.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.drak0.com</link>
	<description>My place to bitch!</description>
	<lastBuildDate>Sat, 03 Oct 2009 00:29:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>WordPress: Automatic plugin upgrade with python</title>
		<link>http://www.drak0.com/2008/12/29/wordpress-automatic-plugin-upgrade-with-python/</link>
		<comments>http://www.drak0.com/2008/12/29/wordpress-automatic-plugin-upgrade-with-python/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 07:10:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.drak0.com/?p=67</guid>
		<description><![CDATA[Since I have been unable to find anything that automagically upgrades wordpress plugins from a script, I decided to write my own in python. This basically logs in and presses the &#8216;upgrade&#8217; button for each of the plugins that have an upgrade available. The script does not support the FTP login for the upgrade process&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Since I have been unable to find anything that automagically upgrades wordpress plugins from a script, I decided to write my own in python.  This basically logs in and presses the &#8216;upgrade&#8217; button for each of the plugins that have an upgrade available.  The script does not support the FTP login for the upgrade process&#8230; so you&#8217;re out of luck if you need that.</p>
<p>I&#8217;ve really only tested this on wordpress 2.7.</p>
<p>Only basic error detection is done, so don&#8217;t blame me if this breaks something <img src='http://www.drak0.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Code follows&#8230;</p>
<p><span id="more-67"></span></p>
<p>The python modules <a href="http://wwwsearch.sourceforge.net/mechanize/" target="_blank">mechanize</a> and <a href="http://www.crummy.com/software/BeautifulSoup/" target="_blank">BeautifulSoup</a> are required.</p>
<pre>
<pre class="brush: python">
#!/usr/bin/python

from mechanize import Browser, FormNotFoundError
from BeautifulSoup import BeautifulStoneSoup
import sys,re

def strip_tags(value):
    &quot;Return the given HTML with all tags stripped.&quot;
    return re.sub(r&#039;&lt;[^&gt;]*?&gt;&#039;, &#039;&#039;, value) 

def usage():
    print &#039;Usage: ./pyWordPressUpgrade.py &lt;url&gt; &lt;username&gt; &lt;password&gt;&#039;
    print &#039;   Where &lt;url&gt; is similar to: http://www.example.com/wp-admin&#039;

if __name__ == &#039;__main__&#039;:
    try:
        host = sys.argv[1]
        username = sys.argv[2]
        password = sys.argv[3]
    except:
        usage()
        sys.exit()

    #plugin name
    name_regex = re.compile(r&#039;plugin=(?P&lt;name&gt;[\w-]*)&#039;)
    #success?
    success_regex = re.compile(r&#039;Plugin upgraded successfully&#039;)
    #ftp connection required
    ftp_regex = re.compile(r&#039;FTP connection information is required&#039;)

    br = Browser()
    br.set_handle_robots(False)
    #br.set_debug_http(True)

    try:
        br.open(host)
        br.select_form(name=&quot;loginform&quot;)
    except Exception, e:
        print &#039;Unable to log into: %s&#039;%host
        print e
        usage()
        sys.exit()

    br[&quot;log&quot;] = username
    br[&quot;pwd&quot;] = password

    r = br.submit()

    # get to the plugin page
    r = br.follow_link(url=&quot;plugins.php&quot;)

    # get all the upgrade links into a list
    upgrade_list = [link for link in br.links(url_regex=&quot;update&quot;)]

    for link in upgrade_list:
        m = name_regex.search( link.url )
        if m:
            print &#039;Updating: %s&#039; % m.group(&#039;name&#039;)
            r = br.follow_link( url=link.url )
            html = r.read()
            soup = BeautifulStoneSoup(html)
            result = str(soup.findAll(&#039;div&#039;, {&#039;class&#039;:&#039;wrap&#039;})[0])
            # strip the html
            result = strip_tags(result)
            m = ftp_regex.search ( result )
            if m:
                print &#039; ++ FAILURE ++&#039;
                print &quot;Sorry, updating plugins via ftp not supported&quot;
                break
            # search for the success string
            m = success_regex.search(result)
            if m:
                print &#039;  ==&gt; success!&#039;
            else:
                print &#039; ++ FAILURE ++&#039;
                print result
                print &#039; +++++++++++++&#039;
            br.back()

    print &quot;Done!&quot;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.drak0.com/2008/12/29/wordpress-automatic-plugin-upgrade-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
