-
Notifications
You must be signed in to change notification settings - Fork 0
/
BDSfunctions_ABACodes.py
74 lines (60 loc) · 1.87 KB
/
BDSfunctions_ABACodes.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
BDS functions for extracting six letter codes from text file produced
by BDSspider_ABACodes.py
"""
file = "codes.txt"
# read and get all codes
def getAllCodes():
infile = open(file, "r")
codes = {}
for line in infile:
# this and the next if/else statement ensure that only codes are kept, not headers
if line[:5].isupper() == True:
line_split = line.rstrip("\n").split(" ")
if len(line_split) == 2:
key = line_split[0]
value = line_split[1]
# if the dash stays in for some weird reason
if value[0] == "-":
# remove the dash and extra spaces
value = value[3:]
else:
pass
codes[key] = value
else:
pass
else:
pass
return codes
def getParulidaeCodes():
infile = open(file, "r")
codes = {}
isParulid = False
for line in infile:
if line[:13] == "WOOD-WARBLERS":
isParulid = True
elif line[:11] == "BANANAQUITS":
isParulid = False
elif isParulid == True and line[:5].isupper() == True and line[:12] != "WOOD-WARBLERS" and line[:10] != "BANANAQUITS":
line_split = line.rstrip("\n").split(" ")
if len(line_split) == 2:
key = line_split[0]
value = line_split[1]
if value[0] == "-":
value = value[3:]
else:
pass
codes[key] = value
else:
pass
return codes
def getOutput(codes):
outfile = open("listofcodes.txt", "w")
for k in codes.keys():
print(k, file = outfile)
outfile.close()
def main():
codes = getParulidaeCodes()
getOutput(codes)
if __name__ == "__main__":
main()