Penn State ACM Magnetic Card Check-in Script

The other officers and I of the PSU ACM have been talking about implementing a magnetic card based check-in system for our meetings and other events. When you check-in (swipe your card) you would receive a certain number of points. The member with the most points at the end of the semester would win a prize like most likely a half eaten bag of Skittles or something. I found the whole project interesting so I took it up and had the whole thing working in just under a day.

Skip to the bottom for a link to the full source.

To formalize… the goal: Write a program that reads data from a magnetic card, queries a database for the card info, and updates a points field in the database. It must also have an option to display the current point values of everyone in the database and run under the best OS ever, Linux.

So how does it all work?

First, and most importantly, I needed a card reader! After looking into cards readers a little bit I determined that the best option was to get one that emulated a keyboard (which is apparently most of them). This way, the program could just use a regular input statement to get the info off the card. At the end of the day, I ended up going with the Magtek 21040108. It’s a no-frills card reader; that is, it reads all three tracks and gets the job done.

With a card reader acquired it was time to turn my attention to the database. This part was easy, I set up a new database on our web server with the following structure:

1
2
3
4
cardID varchar primary key
accessID varchar
points int
lastCheckin timestamp on update

The cardID is the info directly from the cards. This is absolutely guaranteed to be unique so it is a natural choice for the primary key. We also want to keep track of the time of last check-in which will automatically update with the current time whenever a record is updated, but more on this later. With the database design complete, it was time to write some code.

I decided to take this opportunity to become acquainted with Python. I had wanted to play with Python for a long time and this seemed like the perfect opportunity, and the perfect application for it.

After writing a quick Hello World program to become familiar with the new little nuances of a new language, I went searching for a way to talk to MySQL through Python. Enter the MySQLdb module. Import that sucka’, read the manual, and you’re off and running.

So, let’s take a look at some of the more interesting parts of the code.

Hello World!

I can put it off no longer… time to finally start a blog.

About what you say? I haven’t the slightest idea! Whatever I’m interested in for a given week. How’s that? Cool? Cool.

Thus, without further ado… blog!