-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_old_gas_files.py
31 lines (27 loc) · 1.52 KB
/
delete_old_gas_files.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
from datetime import datetime, timedelta, date
# calculate and format a date that is 90 days prior to the current date
prev = date.strftime(datetime.today() - timedelta(days=90), '%Y-%m-%d')
with open('/Users/annanguyen/Documents/Anna_Projects/Web_Scraping_Python_projects/Regular_Gas.csv', 'r+') as dates:
# build a list of dates that are greater than *prev*
d = [s for s in dates if s.strip() > prev]
dates.seek(0) # seek to start of file
dates.write(''.join(d)) # write the list
dates.truncate() # truncate
with open('/Users/annanguyen/Documents/Anna_Projects/Web_Scraping_Python_projects/Midgrade_Gas.csv', 'r+') as dates:
# build a list of dates that are greater than *prev*
d = [s for s in dates if s.strip() > prev]
dates.seek(0) # seek to start of file
dates.write(''.join(d)) # write the list
dates.truncate() # truncate
with open('/Users/annanguyen/Documents/Anna_Projects/Web_Scraping_Python_projects/Premium_Gas.csv', 'r+') as dates:
# build a list of dates that are greater than *prev*
d = [s for s in dates if s.strip() > prev]
dates.seek(0) # seek to start of file
dates.write(''.join(d)) # write the list
dates.truncate() # truncate
with open('/Users/annanguyen/Documents/Anna_Projects/Web_Scraping_Python_projects/Diesel_Fuel_Gas.csv', 'r+') as dates:
# build a list of dates that are greater than *prev*
d = [s for s in dates if s.strip() > prev]
dates.seek(0) # seek to start of file
dates.write(''.join(d)) # write the list
dates.truncate() # truncate