<?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>su.percilio.us &#187; python</title>
	<atom:link href="http://su.percilio.us/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://su.percilio.us</link>
	<description>Haughtily disdainful or contemptuous</description>
	<lastBuildDate>Tue, 06 Apr 2010 15:58:28 +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>Convio Web Services in Python and PHP</title>
		<link>http://su.percilio.us/2009/10/convio-web-services-in-python-and-php/</link>
		<comments>http://su.percilio.us/2009/10/convio-web-services-in-python-and-php/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 17:42:20 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Nerdities]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[convio]]></category>
		<category><![CDATA[cws]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[suds]]></category>

		<guid isPermaLink="false">http://su.percilio.us/?p=137</guid>
		<description><![CDATA[Expanding on my last post about being able to successfully connect to Convio Web Services in three lines, I&#8217;d like to get a little more in depth and actually construct the necessary SOAP headers and make a simple call. I&#8217;ve written a small PHP implementation as well. I was able to make a successful log [...]]]></description>
			<content:encoded><![CDATA[<p>Expanding on my last post about being able to successfully connect to Convio Web Services in three lines, I&#8217;d like to get a little more in depth and actually construct the necessary SOAP headers and make a simple call. I&#8217;ve written a small PHP implementation as well. I was able to make a successful log in to CWS in just <em>2 lines</em> of PHP code!</p>
<div style="text-align: center; margin-bottom: 10px"><img class="size-medium wp-image-117" style="border: 1px solid #ccc; padding: 5px; margin: 0 auto; background: none" src="http://su.percilio.us/wp-content/uploads/2009/10/convio_logo-300x160.gif" alt="Convio Logo" title="Convio Logo" width="300" height="160"  /></div>
<p>Now, as far as CWS goes, Python and PHP may not instantly be an obvious choice as far as languages go, mainly because they are both largely scripting languages. CWS is mainly for robust data syncing operations and those tasks generally go to languages like Java or C#, however, I&#8217;m a high level language guy, so I  go with what I know. Also, Python and PHP both make SOAP exceedingly easy to work with, so there&#8217;s no real reason why you can&#8217;t, with a bit of discipline, write a perfectly excellent and robust data sync operation in either of these languages &#8230; especially Python.</p>
<p>So, here are my examples. They are exceedingly simple and easy once again. The Python example leverages suds once again and the PHP example is using PHP&#8217;s pretty impressive built in SOAP library. Each example shows you how to create the SOAP client using the Convio WSDL, make a successful log in to CWS, create a valid session header for subsequent calls, and how to make a call that grabs the number of constituents that have been added to the Convio database.</p>
<p>If you find either of these examples helpful, please let me know! Keep in mind these are just functional examples. There is no proper error handling or any sort of architecture here; they are just some bare bones examples on how to get data from CWS.</p>
<p><strong>Python</strong></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> suds.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> Client
&nbsp;
<span style="color: #808080; font-style: italic;"># Load the WSDL                                                                                                                                                                                                                                </span>
client = Client<span style="color: black;">&#40;</span><span style="color: #483d8b;">'https://secureX.convio.net/1.0/CLIENT/wsdl'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Log in to CWS                                                                                                                                                                                                                                </span>
login = client.<span style="color: black;">service</span>.<span style="color: black;">Login</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'apiadmin'</span>, <span style="color: #483d8b;">'password'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the session header                                                                                                                                                                                                                       </span>
session = client.<span style="color: black;">factory</span>.<span style="color: black;">create</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Session'</span><span style="color: black;">&#41;</span>
session.<span style="color: black;">SessionId</span> = login.<span style="color: black;">SessionId</span>
client.<span style="color: black;">set_options</span><span style="color: black;">&#40;</span>soapheaders=session<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Get the number of constituents added since last sync                                                                                                                                                                                         </span>
data = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>PartitionId=<span style="color: #ff4500;">1001</span>, RecordType=<span style="color: #483d8b;">'Constituent'</span>, PageSize=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
response = client.<span style="color: black;">service</span>.<span style="color: black;">GetIncrementalInsertsCount</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">**</span>data<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Show the number of constituents added                                                                                                                                                                                                        </span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'%d constituents have been added since the last sync.'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>response.<span style="color: black;">RecordCount</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p><strong>PHP</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Load the WSDL                                                                                                                                                                                                                               </span>
<span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://secureX.convio.net/1.0/CLIENT/wsdl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Log in to CWS                                                                                                                                                                                                                               </span>
<span style="color: #000088;">$login</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Login</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'UserName'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'apiadmin'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Password'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the session header                                                                                                                                                                                                                      </span>
<span style="color: #000088;">$headerBody</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SessionId'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$login</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SessionId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$header</span>     <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'urn:soap.convio.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Session'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headerBody</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span>__setSoapHeaders<span style="color: #009900;">&#40;</span><span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the number of constituents added since last sync                                                                                                                                                                                        </span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'PartitionId'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1001</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'RecordType'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Constituent'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'PageSize'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetIncrementalInsertsCount</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Show the number of constituents added                                                                                                                                                                                                       </span>
<span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%d</span> constituents have been added since the last sync<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">RecordCount</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fsu.percilio.us%2F2009%2F10%2Fconvio-web-services-in-python-and-php%2F';
  addthis_title  = 'Convio+Web+Services+in+Python+and+PHP';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://su.percilio.us/2009/10/convio-web-services-in-python-and-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Log In to Convio Web Services with three lines of Python</title>
		<link>http://su.percilio.us/2009/10/log-in-to-convio-web-services-with-three-lines-of-python/</link>
		<comments>http://su.percilio.us/2009/10/log-in-to-convio-web-services-with-three-lines-of-python/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 19:16:04 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Nerdities]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[convio]]></category>
		<category><![CDATA[cws]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[suds]]></category>

		<guid isPermaLink="false">http://su.percilio.us/?p=130</guid>
		<description><![CDATA[I was on the look out for a good SOAP library for Python now that I am the new Convio &#8220;API Guy.&#8221; In my search I discovered this library: Suds To test it out I tried making successful connection to Convio Web Services. 1 2 3 from suds.client import Client client = Client&#40;'https://secureX.convio.net/1.0/CLIENT/wsdl'&#41; result = [...]]]></description>
			<content:encoded><![CDATA[<p>I was on the look out for a good SOAP library for Python now that I am the new Convio &#8220;API Guy.&#8221;</p>
<div style="text-align: center; margin-bottom: 10px"><img class="size-medium wp-image-117" style="border: 1px solid #ccc; padding: 5px; margin: 0 auto; background: none" src="http://su.percilio.us/wp-content/uploads/2009/10/convio_logo-300x160.gif" alt="Convio Logo" title="Convio Logo" width="300" height="160"  /></div>
<p>In my search I discovered this library:</p>
<p><a href="https://fedorahosted.org/suds/" target="_blank">Suds</a></p>
<p>To test it out I tried making successful connection to Convio Web Services.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> suds.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">import</span> Client
client = Client<span style="color: black;">&#40;</span><span style="color: #483d8b;">'https://secureX.convio.net/1.0/CLIENT/wsdl'</span><span style="color: black;">&#41;</span>
result = client.<span style="color: black;">service</span>.<span style="color: black;">Login</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'apiadmin'</span>, <span style="color: #483d8b;">'password'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Boom. Straight in, no fuss no muss. Pretty impressive. I&#8217;m going to play with Suds and CWS a bit more to see if there is actually a robust Python based syncing application that can be made here. I&#8217;m led to believe Suds is not great for creating SOAP servers, but it makes for a very &#8220;Pythonic&#8221; and easy to understand way to create a SOAP client.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fsu.percilio.us%2F2009%2F10%2Flog-in-to-convio-web-services-with-three-lines-of-python%2F';
  addthis_title  = 'Log+In+to+Convio+Web+Services+with+three+lines+of+Python';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://su.percilio.us/2009/10/log-in-to-convio-web-services-with-three-lines-of-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
