-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathfix_ofxid.py
More file actions
executable file
·27 lines (25 loc) · 839 Bytes
/
fix_ofxid.py
File metadata and controls
executable file
·27 lines (25 loc) · 839 Bytes
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
#!/usr/bin/python
import re
import sys
first_line = False
ofxline = None
with open(sys.argv[1]) as f:
for line in f.readlines():
md = re.match(r"^(19|20)[0-9][0-9]", line)
if md is not None:
# Mark the next line as the first line in a txn
first_line = True
else:
if first_line:
first_line = False
# Check if there is an ofxid on this line
md = re.match(r"^\s+; ofxid:", line)
if md is not None:
ofxline = line
continue
# In every case except the one above where we call next, print the line
sys.stdout.write(line)
# We had a misplaced ofxid last, print it now
if ofxline:
sys.stdout.write(ofxline)
ofxline = None