-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfix.py
45 lines (41 loc) · 1.74 KB
/
fix.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
36
37
38
39
40
41
42
43
44
45
import sys
import re
count = 0 # count the entries and use it as an index value
with open(sys.argv[2], "w") as outfile:
with open(sys.argv[1], "r") as infile:
for line in infile:
#line = line.replace('~', ' ')
line = re.sub(r'[\{\}\^\\]', '', line)
line = re.sub(r'\\\'', '', line)
match = re.match(r'([ ]*)', line)
if match is not None and len(match.groups()) > 0 and len(match.groups()[0]) == 4:
# This is the start of a record
line = ' - id: ' + line.strip().replace(':','').replace('-','') + '\n'
outfile.write(line)
# if line[0] == '-':
# # begining of record
# # Always seem to be `- AUTHOR:`
# # Replace with `- bib:` and move author to the next line
# outfile.write(' - bib: "'+str(count)+'"\n')
# outfile.write(' '+line[1:].strip()+'\n')
# count = count + 1
# elif line.strip()[0] == '-':
# # This line is indented and has a dash
# # Assume it's a name
# # Deal with bibtex inverted names
# # Remove tildes
# names = line.strip()[1:].split(',')
# name = ''
# if len(names) > 1:
# # flip the order
# name = ' '.join([names[1].strip(), names[0].strip()])
# else:
# name = names[0]
# outfile.write(' - name: "'+name.strip()+'"\n')
# else:
# # This line should be fine as is
# # if line.count(':') > 1:
# # line = re.sub(r'([\s]+[A-Z]+:\s)([\w\s:\-\(\),]+\Z)', r'\1"\2"', line[:-1])
# # else:
# line = line[:-1]
# outfile.write(' '+line+'\n')