endperform.org

Musings from /dev/random

Browsing Posts tagged coding

Scripting

Comments off

So lately with work, I’ve been having to come up with some scripts to do some repetitive things on customer sites. Most are one-off scripts, but either way, it’s been both a blessing and a curse. Blessing because I’m coding things, curse because I’m using some tools I’m not used to, such as Awk. With that in mind, I’ve decided that I should probably start brushing up on my script-fu. It used to be, back at work in PA, when I had a task where a script was involved, I’d break out some Perl and throw something together. I can’t really remember the last time I’ve had to use Perl. It’s been about two years now, I estimate.

As I find some resources, I’ll share them here, or else on my delicious.com account. Keep an eye on the lifestream page to see what I’ve been tagging, uploading, or tweeting about.

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’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
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

Comments are welcome, just be gentle. I know some variables are short, but I’ll fix that up on the next iteration

I hadn’t updated on the status of my little Emacs experiment lately, simply because I’ve gravitated away from it. Of late, I’ve been back to using Vi(m) or whatever else is available to me to do things. I know enough about Emacs that I can get into a file, edit it and get back out, but that’s about the extent of my knowledge. I’ve decided that I’m going to wander back to Vim-land and be happy with that editor. Granted, Emacs is pretty cool, but I’ve used Vim the most and I plan to expand my Vim knowledge a bit more, and hopefully reduce me dependence on GUI-based IDEs in the future. I wouldn’t say it was a waste of time, but it just affirms the fact that I dig Vim a bit more than I do Emacs.

I’m becoming a little annoyed with Emacs now. While it’s been pretty ok to use on a day-to-day basis for notes and other text chores, getting down and actually coding with it is quite, at least to me, annoying. My biggest problem is auto-indent. I can’t seem to shut this feature off to save my life, and it drives me insane. It seems to vary depending on the mode I’m in (php, python, etc), and the modes seem to override the settings in my .emacs file. While I do enjoy planner mode, the coding side of Emacs is basically annoying the heck out of me right now, and with what I’m working on, I’m thinking an IDE is going to suit me better in the long run. I may find the exact formula to change the behavior, but lately I’m not all that interested in that, rather than finding what’s going to be the most comfortable setup for me.

So, I’m closing in on the end of my first week with Emacs. So far, things are going about as I expected them to be. I have started my own cheatsheet (which I may publish later), and I’ve installed Planner, which is a really great mode for organizing. It depends on a couple of other things, but once installed, it works well. I’m finding that it’s a nice tool as far as work goes when it comes to organization. I haven’t done much real coding in Emacs yet, simply because I’m still looking for a project to do. Coding at work has been slow because I haven’t had time to work on the internal web applications and there hasn’t been an opportunity for a cool bash script lately.

So, what do I have on my list of things to learn?

- Keybindings. This is going to take a while, but once I learn them then I’ll be in good shape

- .emacs. I’m sure there are some settings that some would see as essential. I’ll share mine in an upcoming post.

As far as projects go, I think I might start taking a look around at the open source projects out there and see if there’s something I can do to start getting involved. I think I’ll also work on setting up local source control on this machine to make managing things easier



© 2010 endperform.org - Powered by geekery, beer and a warped mind.