Skip to content

Commit

Permalink
#980 other verifyHeader bug fix + bulletin rebuilding bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andreleblanc11 committed May 27, 2024
1 parent 6e07842 commit 0f2890b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 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
4 changes: 2 additions & 2 deletions sarracenia/flowcb/gather/am.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ def correctContents(self, bulletin, bulletin_firstchars, lines, missing_ahl, bul

# Check if the header is okay before proceeding to correcting rest of bulletin.
# We want to verify the header AFTER all the contents have been corrected
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

if reconstruct == 1:
new_bulletin, lines = self.reconstruct_bulletin(lines, new_bulletin)
new_bulletin, lines = self.reconstruct_bulletin(lines, new_bulletin=b'')

return new_bulletin , isProblem

Expand Down

0 comments on commit 0f2890b

Please sign in to comment.