-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlunch_methods.py
36 lines (34 loc) · 1.19 KB
/
lunch_methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import datetime
def open_data(dir_loc, file, opentype): #Open the file in the given location and read/write type and return the infile
directory = ('%s\%s' %(os.getcwd(), dir_loc)) #Generate directory path
if not os.path.exists(directory): #Create a new directory for the data if it doesn't already exist
os.makedirs(directory)
location=('%s/%s' %(dir_loc, file)) #Generate the location of the specific data file
try:
open(location, 'x') #Try to create a new file if it doesn't already exist
except OSError as e:
pass
infile=open(location, opentype) #Open the given file with the given method and return
return infile
def clean_dates():
remove=[]
today = datetime.datetime.now()
infile=open_data('data', 'dates.dat', 'r')
lines=infile.readlines()
for line in lines:
print(line)
split=line.split()
day=split[1].split('/')
print(day)
if(int(day[2])<=today.year):
if(int(day[0])<=today.month):
if(int(day[1])<(today.day-1) or int(day[2])<today.year or int(day[0])<today.month):
remove.append(split[1])
infile.close()
infile=open('data/dates.dat', 'w')
print(remove)
for line in lines:
date=line.split()[1]
if date not in remove:
infile.write(line)