Skip to content

Commit

Permalink
fixing merge
Browse files Browse the repository at this point in the history
  • Loading branch information
zachseifts committed Nov 21, 2012
1 parent 28e0bd2 commit 18ca536
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/wid
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class Main(object):
command = commands.UpdateShowCommand(week=self.week)
command.run()

def command_todo(self):
command = commands.TodoCommand(message=self.message, tags=self.tags)
command.run()

def command_notfound(self):
print u'The command was not found'
exit(1);
Expand Down
35 changes: 35 additions & 0 deletions whatidid/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,38 @@ def run(self):
except ValueError:
print u'There are no messages.'


class TodoCommand(Command):
''' Implements a class for the todo command.
'''

def __init__(self, **kwargs):
self.message = kwargs.get('message', None)
self.tags = kwargs.get('tags', [])
super(TodoCommand, self).__init__(**kwargs)

def run(self):
data_path = self.get_data_path('todo')

try:
with open(data_path, 'rb') as fp:
existing_data = json.load(fp)
except ValueError:
existing_data = []

if self.message:
m = hashlib.md5()
created = int(time())
m.update(str(created) + self.message)
existing_data.append({
'id': m.hexdigest(),
'created': created,
'tags': self.tags,
'message': self.message}
)
with open(data_path, 'wb') as fp:
data = json.dump(existing_data, fp, sort_keys=True, indent=4)
else:
print u'No todo item specified'
exit(1)

0 comments on commit 18ca536

Please sign in to comment.