commit 08b1cb5179464ec49e3338a4050366db9ca5663f
Author: dsorber <david.sorber@gmail.com>
Date:   Sun Feb 3 11:46:51 2013 -0500

    Adding keypress counter and renamer scripts.

diff --git a/keypress counter/keypress_counter.c b/keypress counter/keypress_counter.c
new file mode 100644
index 0000000..9db40eb
--- /dev/null
+++ b/keypress counter/keypress_counter.c	
@@ -0,0 +1,119 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <linux/input.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <termios.h>
+#include <signal.h>
+ 
+
+void perror_exit(char *error)
+{
+    perror(error);
+    printf("\nexiting...(%d)\n", 9);
+    exit(0);
+}
+ 
+int main(int argc, char *argv[])
+{
+    uint32_t counter;
+    struct input_event ev[64];
+    int fd, rd, value;
+    int size = sizeof(struct input_event);
+    char name[256] = "Unknown";
+    char *device = NULL;
+    
+    FILE *out_file; 
+     
+    // Make sure the user is root
+    if ((getuid ()) != 0) 
+    {
+        printf ("\nYou must be root to display keypress counts.\n\n");
+        exit(0);
+    }
+ 
+    // Setup check
+    if (argv[1] == NULL)
+    {
+        printf("Please specify (on the command line) the path to the dev event interface device\n");
+        exit(0);
+    }
+
+    if (argc > 1)
+    {
+        device = argv[1];   
+    }
+ 
+    if (argc > 2) 
+    {
+        out_file = fopen(argv[2], "w");
+        if (out_file == NULL)
+        {
+            printf("Unable to open file %s", argv[2]);
+            exit(0);
+        }
+    }
+    
+    // Open specified device
+    if ((fd = open (device, O_RDONLY)) == -1) 
+    {
+        printf("%s is not a vaild device.\n", device);
+        exit(0);
+    }
+    
+    // Print device name
+    //ioctl (fd, EVIOCGNAME(sizeof(name)), name);
+    //printf ("Reading From : %s (%s)\n", device, name);
+    
+    // Main loop, read
+    counter = 0;
+    while(1)
+    {
+        if ((rd = read(fd, ev, size * 64)) < size) 
+        {
+            perror_exit("read()");
+        }
+    
+        value = ev[0].value;
+    
+        // Only read the key press event
+        if (value != ' ' && ev[1].value == 1 && ev[1].type == 1)
+        { 
+            counter++;
+            
+            // If a filename was given, output to that file
+            if (argc > 2)
+            {
+                // Seek to beginning of file, output and flush to file
+                fseek(out_file, 0, SEEK_SET);
+                fprintf(out_file, "%10u", counter);
+                fflush(out_file);
+            } 
+            else
+            {
+                // Otherwise print to stdout
+                // Print count, fixed width of 10 spaces, over of the same line                
+                printf("\r%10u", counter);
+                fflush(stdout);
+            }
+            
+            // Check for (hopefully rare) overflow condition
+            if (counter == UINT32_MAX)
+            {
+                printf("\nGADZOOKS BATMAN!!! You overflowed a 32 bit unsigned integer with all your keystrokes!\n\n");
+                counter = 0;
+            }
+        }
+    }
+    
+    fclose(out_file);
+    return 0;
+}
diff --git a/keypress counter/keypress_wrapper.sh b/keypress counter/keypress_wrapper.sh
new file mode 100755
index 0000000..6924680
--- /dev/null
+++ b/keypress counter/keypress_wrapper.sh	
@@ -0,0 +1,24 @@
+#!/bin/bash
+#
+# Keypress counter wrapper
+#
+./keypress_counter /dev/input/by-path/platform-i8042-serio-0-event-kbd /home/dsorber/Desktop/keypress_count.txt &
+KC_PID=$!
+echo $KC_PID
+sleep 30s
+echo "`date +%F` `cat /home/dsorber/Desktop/keypress_count.txt`" >> keypress_totals.txt
+kill -15 `echo $KC_PID`
+
+./keypress_counter /dev/input/by-path/platform-i8042-serio-0-event-kbd /home/dsorber/Desktop/keypress_count.txt &
+KC_PID=$!
+echo $KC_PID
+sleep 30s
+echo "`date +%F` `cat /home/dsorber/Desktop/keypress_count.txt`" >> keypress_totals.txt
+kill -15 `echo $KC_PID`
+
+./keypress_counter /dev/input/by-path/platform-i8042-serio-0-event-kbd /home/dsorber/Desktop/keypress_count.txt &
+KC_PID=$!
+echo $KC_PID
+sleep 30s
+echo "`date +%F` `cat /home/dsorber/Desktop/keypress_count.txt`" >> keypress_totals.txt
+kill -15 `echo $KC_PID`
diff --git a/renamer/renamer.py b/renamer/renamer.py
new file mode 100644
index 0000000..f8ec300
--- /dev/null
+++ b/renamer/renamer.py
@@ -0,0 +1,29 @@
+import os
+import re
+import sys
+
+def main():
+    
+    if len(sys.argv) < 3:
+        print 'Not enough arguments specified!'
+        return
+
+    show_name = sys.argv[1]
+    directory = sys.argv[2]
+
+    show_name = show_name.replace(' ', '\.')
+
+    for filename in os.listdir(directory):
+        m = re.match("^(%s)\.S(\d+)E(\d+)\.(.*)\.(\w{3})$" % show_name, filename, re.IGNORECASE)
+        if m:
+            new_name = '%s - S%sE%s.%s' % (show_name.replace('\.', ' '), 
+                                           m.group(2), m.group(3), m.group(5).lower())
+
+            print '%s --- MATCH: %s' % (filename, new_name)
+            os.rename(os.path.join(directory, filename), 
+                      os.path.join(directory, new_name))
+        else:
+            print filename
+
+if __name__ == '__main__':
+    sys.exit(main())
\ No newline at end of file
