This repository was archived by the owner on Apr 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetdays2.py
More file actions
43 lines (36 loc) · 1.38 KB
/
getdays2.py
File metadata and controls
43 lines (36 loc) · 1.38 KB
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
36
37
38
39
40
41
42
import csv
import itertools
from datetime import datetime, timedelta
inputfile = 'outputgeo1aug.csv'
matchoutputfile = 'daysfound.csv'
alldays = [['today', timedelta(days=0)],
['this day', timedelta(days=0)],
['tomorrow', timedelta(days=1)],
['to-morrow', timedelta(days=1)],
['Sunday next', timedelta(days=8)],
['Sunday', timedelta(days=1)],
['Monday', timedelta(days=2)],
['Tuesday', timedelta(days=3)],
['Wednesday', timedelta(days=4)],
['Thursday', timedelta(days=5)],
['Friday', timedelta(days=6)],
['Saturday', timedelta(days=7)]]
with open(inputfile) as csvfile:
reader = csv.reader(csvfile)
headers = next(reader)
with open(matchoutputfile,'w') as matchfile:
writermatch = csv.writer(matchfile)
newheaders = list(headers).append('meeting date')
writermatch.writerow(headers) # add csv column
for row in reader: #itertools.islice(reader,5):
meetingText = row[0].lower()
paperdate = datetime.strptime(row[7], '%d/%m/%Y')
for (day, dayOffset) in alldays:
ind=meetingText.find(day.lower())
if not ind==-1:
meetingdate = paperdate + dayOffset
newrow = list(row)
newrow.append('%02d/%02d/%d' % (meetingdate.day, meetingdate.month, meetingdate.year))
writermatch.writerow(newrow)
if day=='Sunday next': #special case 'sunday next' so doesn't also match 'sunday'
meetingText = meetingText.replace('sunday next', 'xunday next')