<?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>/home/brad &#187; python</title>
	<atom:link href="http://www.endperform.org/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.endperform.org</link>
	<description>My corner of the web</description>
	<lastBuildDate>Thu, 08 Jul 2010 18:13:51 +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>Python Example: Check for open SSH</title>
		<link>http://www.endperform.org/2009/01/python-example-check-for-open-ssh/</link>
		<comments>http://www.endperform.org/2009/01/python-example-check-for-open-ssh/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 01:56:32 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/?p=382</guid>
		<description><![CDATA[I posted this bit of code some time ago as pysync.py, but I wanted to present it again in it&#8217;s latest form. Right now, all it does is print a message stating whether or not it has an SSH port open. This can be used as the basis of a script to do something based [...]]]></description>
			<content:encoded><![CDATA[<p>I posted this bit of code some time ago as pysync.py, but I wanted to present it again in it&#8217;s latest form.  Right now, all it does is print a message stating whether or not it has an SSH port open.  This can be used as the basis of a script to do something based on an open SSH port.  The port could also be changed to check for HTTP, telnet or what have you.</p>
<pre>
'''
Python code to check if SSH is open on a server
Updated: January 23, 2009

Brad Peters
brad (at) endperform (dot) org
'''

import socket
import os

'''
This code actually attempts to check the SSH port
'''
def checkServer():
    serverSocket = socket.socket()
    serverSocket.settimeout(0.25)
    try:
        serverSocket.connect(("192.168.1.20", 22))
    except socket.error:
        return 1

'''
If status is defined, we know the connection failed
'''
status = checkServer()
if status:
    print "Server is down"
else:
    print "I can ssh!"
</pre>
<p>This code is free, use it as you like.  I just wanted to present it to show what I&#8217;ve been messing with.  I have an idea for this at work.  I haven&#8217;t messed with classes yet, but that&#8217;s next on my agenda.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2009/01/python-example-check-for-open-ssh/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>When a lull strikes</title>
		<link>http://www.endperform.org/2008/10/when-a-lull-strikes/</link>
		<comments>http://www.endperform.org/2008/10/when-a-lull-strikes/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 20:17:10 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/?p=312</guid>
		<description><![CDATA[I came up with something to parse some mbox-format email files out of boredom. The final step, coming later, is taking the data and making a line graph out of it. I&#8217;m sure it can be done a lot better, but at any rate, may I present the beginnings of mail-graph.py import mailbox import sys [...]]]></description>
			<content:encoded><![CDATA[<p>I came up with something to parse some mbox-format email files out of boredom.  The final step, coming later, is taking the data and making a line graph out of it.  I&#8217;m sure it can be done a lot better, but at any rate, may I present the beginnings of mail-graph.py</p>
<pre>
import mailbox
import sys
import os

months = {'Jan': '01', 'Feb': '02', 'Mar': '03',
		  'Apr': '04', 'May': '05', 'Jun': '06',
          'Jul': '07', 'Aug': '08', 'Sep': '09',
		  'Oct': '10', 'Nov': '11', 'Dec': '12'}
emails = {}
total = 0

def accumulate_counts(email):
	for message in email:
		date = message['date']
		split_date = date.split()
		day = split_date[1]
		month = split_date[2]
		year = split_date[3]
		monthnum = months.get(month, 0)
		yearmonth = year + monthnum

		count = emails.get(yearmonth, 0)
		if (count == 0):
			emails[yearmonth] = 1
		else:
			emails[yearmonth] += 1

mbox_path = sys.argv[1]

for root, dirs, fileNames in os.walk(mbox_path):
	for fileName in fileNames:
		path = os.path.join(root, fileName)

		mbox = mailbox.mbox(path)
		accumulate_counts(mbox)

for m, e in emails.iteritems():
	print m, e
	total += e

print total
</pre>
<p>Comments are welcome, just be gentle.  I know some variables are short, but I&#8217;ll fix that up on the next iteration</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2008/10/when-a-lull-strikes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IDEs, Django and more</title>
		<link>http://www.endperform.org/2008/04/ides-django-and-more/</link>
		<comments>http://www.endperform.org/2008/04/ides-django-and-more/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 17:27:57 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/?p=231</guid>
		<description><![CDATA[There&#8217;s a lot of talk lately on some of the blogs I read about code editors. I myself have been dealing with finding one that suits me (even if I don&#8217;t code all that often anymore), and so far, nothing seems to fit 100% yet. I&#8217;ve got a basic understanding of Vim, Emacs and Nano, [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a lot of talk lately on some of the blogs I read about code editors.  I myself have been dealing with finding one that suits me (even if I don&#8217;t code all that often anymore), and so far, nothing seems to fit 100% yet.  I&#8217;ve got a basic understanding of Vim, Emacs and Nano, which are all ok as far as command line utilities go.  I think I fall into the IDE category when it comes to coding, so I&#8217;ve been playing around with jEdit, Eclipse and most recently OpenKomodo.  OpenKomodo seems to work pretty well, and I really like the completion aspect of it, so I think I&#8217;m going to stick with it for coding for now.  For configuration editing / remote work, I&#8217;ll stick with Vim.</p>
<p>My Django experiment is going relatively well.  The database model is done, and now I&#8217;m at the point where I&#8217;m a bit stuck.  I&#8217;m still learning my way around the framework, so I&#8217;m sure I&#8217;ll get it with time.  What I&#8217;m currently dealing with right now is trying to figure out views.  The way I understand it so far is that <code>urls.py</code> defines what happens when you go to a particular URL for the project, such as http://project/view/main_page, then in views.py there would be a <code>main_page</code> routine.  Part of my hang up right now is the design aspect.  In a nutshell, I&#8217;m trying to retrofit an old PHP application into Django while not altering it too much.  I&#8217;m in no hurry to finish this, so I have time.  As far as personal projects, I don&#8217;t really have any Django-related projects I could work on for personal things, so I&#8217;ve been thinking about some ideas I can do in just normal python.  PyGame seems rather interesting, and of course I could always find some other project to get into as well.  If you have any thoughts on projects looking for a semi-new Python guy, drop me a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2008/04/ides-django-and-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adventures in Python</title>
		<link>http://www.endperform.org/2008/03/adventures-in-python/</link>
		<comments>http://www.endperform.org/2008/03/adventures-in-python/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 18:19:32 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/?p=227</guid>
		<description><![CDATA[I figured that I&#8217;m going to start yet another series on my blog entitled &#8220;Adventures in Python&#8221;. I figure it will motivate me to play around with Python/Django while sharing my experiences with everyone. Keep in mind I&#8217;m new when it comes to Python, so my code may not be so pretty.]]></description>
			<content:encoded><![CDATA[<p>I figured that I&#8217;m going to start yet another series on my blog entitled &#8220;Adventures in Python&#8221;.  I figure it will motivate me to play around with Python/Django while sharing my experiences with everyone.  Keep in mind I&#8217;m new when it comes to Python, so my code may not be so pretty.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2008/03/adventures-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Learning Python via Django</title>
		<link>http://www.endperform.org/2008/03/learning-python-via-django/</link>
		<comments>http://www.endperform.org/2008/03/learning-python-via-django/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 13:29:17 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/?p=225</guid>
		<description><![CDATA[I&#8217;ve been playing off and on with Python for a while now, but never really did anything too awfully useful. Of late, I&#8217;ve been working on maintaining some internal web applications at work, which are written in PHP. After reading about Django and checking out some documentation, I&#8217;ve set out to rewrite at least one [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing off and on with Python for a while now, but never really did anything too awfully useful.   Of late, I&#8217;ve been working on maintaining some internal web applications at work, which are written in PHP.  After reading about Django and checking out some documentation, I&#8217;ve set out to rewrite at least one of those applications into Django.  Thus far I don&#8217;t have much other than the database layout, but from what I can see I&#8217;ll have something rather functional in a short amount of time.  I wish I had a non work-related project to work on, since I find it hard to work on the rewrite outside of working hours.  Even during working hours my time is limited as I have other responsibilities to deal with, this being the lowest priority.</p>
<p>At any rate, learning more Python via Django seems to be going well so far.  I am branching out, though, trying some new things and playing with some libraries.  I&#8217;ll share some of my things when I finish.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2008/03/learning-python-via-django/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Coding in 2007</title>
		<link>http://www.endperform.org/2007/12/coding-in-2007/</link>
		<comments>http://www.endperform.org/2007/12/coding-in-2007/#comments</comments>
		<pubDate>Mon, 24 Dec 2007 13:11:52 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/2007/12/24/coding-in-2007/</guid>
		<description><![CDATA[I had a lot of ambition in 2007 to start coding things again, but as with every year, most of my thoughts came and went. I have learned enough Python to be dangerous, at least, and I&#8217;m still pretty OK with Perl, although I barely use it anymore. I&#8217;m still messing with a bit of [...]]]></description>
			<content:encoded><![CDATA[<p>I had a lot of ambition in 2007 to start coding things again, but as with every year, most of my thoughts came and went.  I have learned enough Python to be dangerous, at least, and I&#8217;m still pretty OK with Perl, although I barely use it anymore.  I&#8217;m still messing with a bit of PHP as well since I deal with it at work, but I&#8217;ve been thinking a lot about rewriting some of our internal webapps using Django.  Problem is that it needs to be maintainable by others in my department, but I&#8217;m thinking if I code them right it shouldn&#8217;t be too horrible.</p>
<p>As far as personal projects go, there&#8217;s not really a whole lot I&#8217;ve found to code up.  I&#8217;ve thought of a couple of things, but never really got into them.  I should, though, so I can sharpen my skills.  I&#8217;ll be working on the work projects at home mostly, but I want to have something I can do for myself, or if nothing else, something else to help out on.  Hopefully in 2008 I&#8217;ll be a bit more inclined to write more code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2007/12/coding-in-2007/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PySync Redux</title>
		<link>http://www.endperform.org/2007/05/pysync-redux/</link>
		<comments>http://www.endperform.org/2007/05/pysync-redux/#comments</comments>
		<pubDate>Mon, 28 May 2007 04:02:47 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/blog/2007/05/28/pysync-redux/</guid>
		<description><![CDATA[After some comments by Patrick, I decided to play around with classes and came up with the latest iteration of my little sync script. I also added a rudimentary log file. import socket, os class Server: """ Server class used for checking and syncing """ def __init__(self, srv): self.server = srv def is_up(self, port): """ [...]]]></description>
			<content:encoded><![CDATA[<p>After some comments by <a href="http://www.haller.ws">Patrick</a>, I decided to play around with classes and came up with the latest iteration of my little sync script.  I also added a rudimentary log file.</p>
<pre>
import socket, os

class Server:
    """ Server class used for checking and syncing """
    def __init__(self, srv):
        self.server = srv

    def is_up(self, port):
        """ Checks for server availability"""
        rmtsocket = socket.socket()
        rmtsocket.settimeout(0.25)
        try:
            rmtsocket.connect((self.server, port))
        except socket.error:
            return 0
        else:
            return 1

    def run_sync():
        """ Run Unison to perform the sync """
        try:
            status = os.system("unison -batch")
        except:
            print "Error running Unison... ", status

def write_log(entry):
    logfile.write(entry + "\n")

logfile = open("pysync.log", "a+")

server = Server("192.168.1.99")
if (server.is_up(22)):
    write_log("Server's up, syncing now")
    server.run_sync()
else:
    write_log("Server is down, no sync performed")

logfile.close()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2007/05/pysync-redux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python First Steps: pysync.py</title>
		<link>http://www.endperform.org/2007/05/python-first-steps-pysyncpy/</link>
		<comments>http://www.endperform.org/2007/05/python-first-steps-pysyncpy/#comments</comments>
		<pubDate>Sun, 27 May 2007 13:06:44 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/blog/2007/05/27/python-first-steps-pysyncpy/</guid>
		<description><![CDATA[So, I finished my first little script. It does nothing but check to see if my desktop is up, and if it is, it will run unison to perform a sync. We all gotta start somewhere, right? import socket import os rmtsock = socket.socket() rmtsock.settimeout(0.25) def checkServer(): try: rmtsock.connect(("192.168.1.50", 22)) except socket.error: return 1 status [...]]]></description>
			<content:encoded><![CDATA[<p>So, I finished my first little script.  It does nothing but check to see if my desktop is up, and if it is, it will run unison to perform a sync.  We all gotta start somewhere, right?</p>
<pre>
import socket
import os

rmtsock = socket.socket()
rmtsock.settimeout(0.25)

def checkServer():
    try:
        rmtsock.connect(("192.168.1.50", 22))

    except socket.error:
        return 1

status = checkServer()
if status == 1:
    print "Server is down"
else:
    rsyncrun = os.system("unison -batch")
    if (rsyncrun):
        return 1
    else:
        return 0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2007/05/python-first-steps-pysyncpy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fatherhood, Django and more</title>
		<link>http://www.endperform.org/2007/05/fatherhood-django-and-more/</link>
		<comments>http://www.endperform.org/2007/05/fatherhood-django-and-more/#comments</comments>
		<pubDate>Tue, 22 May 2007 20:24:13 +0000</pubDate>
		<dc:creator>Brad</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.endperform.org/blog/2007/05/22/fatherhood-django-and-more/</guid>
		<description><![CDATA[I&#8217;m a little behind in my blogging, as I missed out on last week&#8217;s installment of &#8216;The Geeky Dad&#8217;. I&#8217;ll be back this week with a new installment. I just need to figure out what I&#8217;m going to write about. You also might have noticed that the site has been changing a bit. I&#8217;m playing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a little behind in my blogging, as I missed out on last week&#8217;s installment of &#8216;The Geeky Dad&#8217;.  I&#8217;ll be back this week with a new installment. I just need to figure out what I&#8217;m going to write about.  You also might have noticed that the site has been changing a bit.  I&#8217;m playing with themes again, trying to find one that suits me.  I wanted a change, but it seems like most of the themes that I have been looking at just aren&#8217;t exactly what I&#8217;m after.  So, just be warned that the site might change a bit more before it&#8217;s all said and done.</p>
<p>In more domesticated news, I made some lasagna over the weekend, following a recipe in one of the fatherhood books I&#8217;ve been reading.  Other than the tomato sauce being more meat than tomato sauce, it turned out pretty well.  I think with a bit of fine-tuning (and a proper lasagna pan), it will be even better the next go round.  I&#8217;m trying to do all I can around the house for Beth while she&#8217;s pregnant.  Granted, she&#8217;s a big girl and can still take care of things, but it&#8217;s my way of contributing to the pregnancy as a whole.</p>
<p>As far as geeking out goes, I&#8217;ve been playing around a bit with Python and now Django.  Django is a Python-powered web framework, and while I should probably wait until I have a few regular python scripts under my belt, I couldn&#8217;t resist the urge to install it and play around with it. Surprisingly, it&#8217;s pretty straight-forward, and my understanding of Python seems to be a bit more solid than I thought.  My main issue is using Python.  Once I get to using it more often, I&#8217;m sure things will start to become second nature to me.</p>
<p>Oh, and one other thing.  Bethany and I will be heading up to PA for Father&#8217;s day.  I&#8217;m not sure what all we&#8217;ll be doing, but I would imagine we might have a bit of time to meet up with some of my PA friends at some point during the weekend.  That should be pretty fun, I&#8217;m thinking.  She gets to meet my family, I get to take her around my old stomping grounds, and I get a vacation from work.  Sounds like the perfect little getaway to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endperform.org/2007/05/fatherhood-django-and-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
