Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue1036 - Add unit tests for AM code #1044

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sarracenia/bulletin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _verifyYear(self, bulletin_year):

return True

def verifyHeader(self, header):
def verifyHeader(self, header, charset):
"""Derived from Sundew -> https://github.com/MetPX/Sundew/blob/main/lib/bulletin.py#L601-L671.
Verifies the integrity of the bulletin header. Flag if there is an error in the header.
Called by the buildHeader method.
Expand Down Expand Up @@ -92,13 +92,13 @@ def verifyHeader(self, header):
return header, isProblem

# Verify BBB field(s) -> https://www.weather.gov/tg/headef. Remove it if it's corrupted.
if not tokens[3].isalpha() or len(tokens[3]) != 3 or tokens[3][0] not in ['C','A','R','P']:
if not tokens[3].isalpha() or len(tokens[3]) != 3 or tokens[3].decode(charset)[0] not in ['C','A','R','P']:
logger.info("Header normalized: fourth and later fields removed.")
del tokens[3:]
rebuild = 1

if len(tokens) == 5 and \
(not tokens[4].isalpha() or len(tokens[4]) != 3 or tokens[4][0] not in ['C','A','R','P']):
(not tokens[4].isalpha() or len(tokens[4]) != 3 or tokens[4].decode(charset)[0] not in ['C','A','R','P']):
logger.info("Header normalized: fifth and later fields removed")
del tokens[4:]
rebuild = 1
Expand Down Expand Up @@ -249,7 +249,7 @@ def getStation(self, data):
# Added to SR3
# The station needs to be alphanumeric, between 3 and 5 characters. If not, don't assign a station
if re.search('^[a-zA-Z0-9]{3,5}$', station) == None:
station = ''
station = None

return station

Expand Down
2 changes: 1 addition & 1 deletion sarracenia/flowcb/gather/am.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def correctContents(self, bulletin, bulletin_firstchars, lines, missing_ahl, bul
reconstruct = 1

# Check if the header is okay before proceeding to correcting rest of bulletin.
verified_header , isProblem = self.bulletinHandler.verifyHeader(lines[0])
verified_header , isProblem = self.bulletinHandler.verifyHeader(lines[0], charset)
if verified_header != lines[0]:
lines[0] = verified_header
reconstruct = 1
Expand Down
3 changes: 3 additions & 0 deletions sarracenia/flowcb/rename/raw2bulletin.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def rename(self,msg,isProblem):

# with open(new_path, 'w') as f: f.write(data)

logger.error(f"New filename (for problem file): {new_file}")
elif stn_id == None:
new_file = header + "_" + BBB + "_" + '' + "_" + seq + "_PROBLEM"
logger.error(f"New filename (for problem file): {new_file}")
elif ddhhmm == '':
new_file = header + "_" + BBB + "_" + stn_id + "_" + seq
Expand Down
Loading
Loading