Tagged: python

Sync Directory to S3

August 14, 2011 Posted by mitch | boto, python, S3 | 0 Comments

I needed the ability to sync a directory to S3 for a client... so I wrote up a script I'm calling sync2S3.py.  Some of the code came from the Django extensions project, which I modified to work without django and just sync a directory in an rsync like fashion.  Enjoy


I hate monitoring software

April 12, 2010 Posted by mitch | django, hyperic, monitoring, python, twisted, zenoss | 0 Comments

I've been installing a few monitoring solutions... zenoss, hyperic and others... but initial impressions on all of them are lacking... I mean... they're overly complicated, Monitoring and graphing is easy... and having a base setup out of the box isn't to much to ask I don't think... I want something like cloudkick. Simple, elegant... yet appears to be sufficiently flexible. What more could you want? I would say however, I'm fairly disappointed that its a service mostly... means I'm probably not going to use it at all... and maybe if my boss feels sufficiently giving...he'll invest some money and we'll write our own...

Bonus part? Looking at their careers section... python, django, twisted... seems they read my mind... thats the tools I would have used to build one...


New Site Design AND new backend

March 11, 2010 Posted by mitch | django, python, website | 0 Comments

I FINALLY DID IT! can you believe it... I've been saying it for ever... but I finally got some free time at work to work on it... and... its still a work in progress... style sheets need to be finished... some other code needs to be done... I need to bring back my photo albums... which will be new and improved... but... its running django... and my own custom blog app. It seems a little slow to me with me so I'll work on some tuning options, but it runs fast on my laptop... My laptop is quite a bit more powerful than this vhost.... I've disable php from my server!


Updates comming

January 4, 2009 Posted by mitch | django, python, website | 0 Comments

Well... I"ve been playing with Python for work for a couple years now... and over the last 6 months or so, I've been using django for various projects. And I've decided my blog as well as everything else on this site will be replaced by django apps. Some that I will write and others that I will find and download off the net. I've been using and keeping wordpress updated for all these years and well... I have to say, I don't really like it, I don't feel its allowed me to make the sites or extensions that I want within the templates framework they they supply. So, over the next couple months, I will be putting a new site together with a new design as well. The hardest part is going to be getting all my old posts into the new database. Since I don't have many comments (only 4 or so for the years I've been doing it) I'm not going to bother keeping those... as that would make the task even harder... But a new design will come with the site... one I have seen a few examples and have my mind racing over... but I don't know what it will be just yet. should be fun.


To switch my blog software or not

January 27, 2008 Posted by mitch | django, python, website | 0 Comments

I've been using wordpress now for a couple years, and while I don't have any major complaints against it... I think I'd just like "more". Or... maybe I just need to take advantage of the features it has... however... the whole slashdot/digg effect flooding out wordpress servers... not that I think I'll ever get slash dotted, but... what can I say... i'm a geek and I like to tinker occasionally. Currently my biggest reason for not doing anything, is I'd have to rewrite a whole new theme... I spent a good couple hours doing the one I have and I just don't know where I'd find the time to do it again...

So... I guess I wouldn't expect it any time soon.. however i may get bored or suddenly have an urge and alot of time on my hands so you never know... I did come home with a new car last week...


Python SQL SELECT using name LIKE %%s%

April 25, 2007 Posted by mitch | projects, python | 0 Comments

I know I haven't written about much of the code I've written over the last couple years or so... as I don't consider myself a "programmer". I'm a Systems Administrator by trade but with a flare for scripting where I will write scripts to make my job easier (even so I no longer have to do my "job"). I've been learning python over the last year or so, and I think I'm really finally starting to get it and really be able to apply what I've learned to new scripts. Anyway, as a means to help me remember this and that maybe it could be helpful to someone else down the road. I'm not sure if there is a better way to do this or if this is the proper way. But what I was looking for was a way to be able to pass a generic name and do a LIKE sql search for it. My example is actually coming from using bacula at work, and I'm trying to get some better reporting and store some statistics(I will eventually post what I come up with...) Anyway, heres a bit of sample code to illustrate what I came up with(I run a postgresql database, but I don't believe it would be any different for mysql other than the original module).


#!/usr/bin/env python

import sys, psycopg

DSN = "dbname='bacula' user='bacula'"

class pgDB:
def db_connect(self, DSN):
try:
conn = psycopg.connect(DSN)
except StandardError, err:
print "Error: Unable to connec tot the database, exiting...", err
return Exception
else:
return conn
def do_query(self, conn, query, args=[]):
cur = conn.cursor()
try:
cur.execute(query, args)
result = cur.fetchall()
return result
except StandardError, err:
print "Error Executing Query: ", error

def main(clientName):
DB = pgDB()
try:
myDBconn = DB.db_connect(DSN)
except:
sys.exit()

clientName = "%" + clientName + "%"
query = "SELECT * FROM client WHERE name LIKE %s"

result = DB.do_query(myDBconn, query, [clientName])

print result

if __name__ == "__main__":
main("hostname")


Assuming the spacing is all correct, that should work. The key being having to append the %'s to the word we are searching for before it is injected into the predefined query... kinda weird how it does that as i was trying to have the %'s in the query before the clientname was injected having the query look like "LIKE %%s%" which was causing problems... and I suppose I can understand why...

Anyway, as I said, I'm not a programmer by any means, this is just some notes for myself. Maybe they will help someone else too...


Python

October 6, 2005 Posted by mitch | projects, python | 0 Comments

I've decided to learn python. I've been writting a could hacks here and there to get a feel for the language so far so good. The language itself it fairly simple with alot of power packed into it. Reading other peoples code isn't bad either. (Which is the rep perl has...) I'll link up some of my code once its "ready". I just got "Python Cookbook" in the mail today. So I think I'll hit it for the next hour or so and see what happens.


Random Quote:

To do what others cannot do is talent. To do what talent cannot do is genius.

- Will Henry