# done.py: A script to remove an item from 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 are completed items to remove
import sys
if len(sys.argv) > 1:
# Get completed item number(s)
list = sys.argv
list.pop(0)
# Create a blank updated list
updated_list = []
# Read the old list, line by line
f = open(todo_list, 'r')
for line in f:
# Reset remove flag
remove = 0
# Go through list, checking for items to remove
for item in list:
if 1 <= len(item) <= 3:
if line[(3 - len(item)):3] == item:
remove = 1
# Copy items to updated list if they're not to be removed
if remove == 0:
updated_list.append(line[5:])
# Close file
f.close()
# Reopen the file for writing
f = open(todo_list, 'w')
# Write the updated to-do list
i = 0
for new_item in updated_list:
i = i + 1
f.write(str(i).rjust(3) + '. ' + new_item)
# Close file
f.close()