Skip to content

Instantly share code, notes, and snippets.

@hemache
Last active December 10, 2015 07:18
Show Gist options
  • Save hemache/4399936 to your computer and use it in GitHub Desktop.
Save hemache/4399936 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from time import strftime, strptime, mktime
file_name = 'names.lst'
trash_file_name = 'old_names.lst'
filter_date = strftime('%d-%m-%Y') #'01-01-2012'
def timestamp(strtime, format = '%d-%m-%Y'):
return mktime(strptime(strtime, format))
filter_date = timestamp(filter_date)
items = list()
trash_items = list()
with open(file_name) as fl:
for line in fl.readlines():
date = line.rstrip().split(' ')[-1]
if timestamp(date) < filter_date:
print 'Moving', line
trash_items.append(line)
else:
items.append(line)
with open(file_name, 'w') as fl, open(trash_file_name, 'w') as trash_fl:
fl.writelines(items)
trash_fl.writelines(trash_items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment