Skip to content

Commit b7da90a

Browse files
committed
make some code more pythonic; strip <br> tags; don't translate irrelevant text
1 parent 9d1790e commit b7da90a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

NHC.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_tropical_bulletin(bulletin):
5252
for item in items :
5353

5454
desc = item.find('description')
55-
desc = desc.text
55+
desc = desc.text.replace('<br />','')
5656
headers = desc.split("BULLETIN")[1].split("SUMMARY OF")[0]
5757
headers = headers.strip().split("\n")
5858
headers = [line for line in headers if line != '']
@@ -105,14 +105,14 @@ def get_tropical_bulletin(bulletin):
105105

106106
warnings = desc.split("WATCHES AND WARNINGS", 1)[1].split("DISCUSSION AND OUTLOOK",1)[0]
107107
matches = re.findall(r'A ([\w\s]+) is in effect for\.\.\.', warnings)
108-
if warnings.__contains__("There are no coastal watches or warnings in effect.") or len(matches) == 0:
108+
if "There are no coastal watches or warnings in effect." in warnings or len(matches) == 0:
109109
signals["nowarning"] = True
110110

111111

112-
if warnings.__contains__("CHANGES WITH THIS ADVISORY:"):
112+
if "CHANGES WITH THIS ADVISORY:" in warnings:
113113
changes = desc.split("CHANGES WITH THIS ADVISORY:", 1)[1].split("SUMMARY OF WATCHES AND WARNINGS IN EFFECT:",1)[0]
114114

115-
if changes.__contains__("None") or not contains_area(changes, area):
115+
if "None" in changes or not contains_area(changes, area):
116116
signals["noupdate"] = True
117117

118118

@@ -135,16 +135,17 @@ def get_tropical_bulletin(bulletin):
135135
data["events"] = []
136136
for match in matches:
137137
try:
138-
event = {}
139-
event["type"] = match
140-
event["places"] = []
141-
event["relevant"] = False
138+
event = {
139+
'type': match,
140+
'places': [],
141+
'relevant': False
142+
}
142143
index = warnings.index("A " +match+ " is in effect for...") +1
143144
#find all events and for each event places
144145
while index < len(warnings) and warnings[index] != '$':
145146
place = warnings[index].replace("* ", "").strip()
146-
event["places"].append(translate(place))
147-
if place.casefold().__contains__("puerto rico"):
147+
if "puerto rico" in place.casefold():
148+
event["places"].append(translate(place))
148149
event["relevant"] = True
149150

150151

@@ -159,6 +160,8 @@ def get_tropical_bulletin(bulletin):
159160
if event["relevant"] == True :
160161
data["practive"].append(event)
161162
signals["practive"] = True
163+
else:
164+
logger.debug(f"event {event['type']} not deemed relevant")
162165

163166
#hazards affecting land
164167
hazards = desc.split("HAZARDS AFFECTING LAND",1)[1].split("FORECASTER",1)[0]
@@ -177,7 +180,7 @@ def get_tropical_bulletin(bulletin):
177180
sentence = sentence.strip().replace("\n", "")
178181
location_amount = {}
179182

180-
if sentence.__contains__("...") :
183+
if "..." in sentence:
181184

182185
location = sentence.split("...")[0]
183186
height = sentence.split("...")[1]
@@ -192,7 +195,7 @@ def get_tropical_bulletin(bulletin):
192195
location_amount["height"] = translate(height)
193196
count += 1
194197
rainlist.append(location_amount)
195-
elif sentence.__contains__(":"):
198+
elif ":" in sentence:
196199
location = sentence.split(":")[0]
197200
height = sentence.split(":")[1]
198201
if contains_area(location, area):
@@ -219,7 +222,7 @@ def get_tropical_bulletin(bulletin):
219222
surgedata = re.search(surgepattern, hazards, re.DOTALL)
220223

221224
if surgedata:
222-
if surgedata.group(1).__contains__("..."):
225+
if "..." in surgedata.group(1):
223226

224227
surgedata= surgedata.group(1).split("...", 1) [1]
225228
patt= r'([A-Za-z\s.-]+)\.\.\.(\d+\s+to\s+\d+)\s+ft'

0 commit comments

Comments
 (0)