# todo.py: A script to append an item to a numbered to-do list.
# Copyright 2008, Marc Stewart
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# ==== START OF USER-SET PARAMETERS =============
# Set the filename of the to-do list here.
todo_list = "C:/todo.txt"
# ==== END OF USER-SET PARAMETERS ===============
# Check there was actually something to add
import sys
if len(sys.argv) > 1:
# Get new item
list = sys.argv
list.pop(0)
new_item = ' '.join(list)
# Open the current list
f = open(todo_list, 'r+')
# Count current number of items
i = 0
for line in f:
i = i + 1
if i >= 999:
# This system assumes the list will have less than a thousand items
print "This is meant to be an achievable to-do list!"
else:
# Add it as the next line in the list
i = i + 1
f.write(str(i).rjust(3) + '. ' + new_item + "\n")
# Close file
f.close()