Compare commits
2 commits
69e01d73e1
...
2afcf59ba0
Author | SHA1 | Date | |
---|---|---|---|
2afcf59ba0 | |||
f917ba20bd |
3 changed files with 33 additions and 24 deletions
|
@ -4,30 +4,8 @@ import argparse
|
||||||
|
|
||||||
from xmet.db import Database
|
from xmet.db import Database
|
||||||
from xmet.afos import AFOSMessageParser
|
from xmet.afos import AFOSMessageParser
|
||||||
|
from xmet.util import each_chunk
|
||||||
|
|
||||||
CHUNK_SIZE = 4096
|
|
||||||
|
|
||||||
def each_chunk(fh, sep: str):
|
|
||||||
buf = ''
|
|
||||||
|
|
||||||
while True:
|
|
||||||
chunk = fh.read(CHUNK_SIZE)
|
|
||||||
|
|
||||||
if chunk == '' or chunk is None:
|
|
||||||
yield buf.strip()
|
|
||||||
break
|
|
||||||
|
|
||||||
buf += chunk
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
part, buf = buf.split(sep, 1)
|
|
||||||
except ValueError:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
yield part.strip()
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description = 'Ingest National Weather Service text bulletin products'
|
description = 'Ingest National Weather Service text bulletin products'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from xmet.vtec import VTECEvent, VTECHydroEvent
|
||||||
RE_ID = re.compile(r'^(\d+)$')
|
RE_ID = re.compile(r'^(\d+)$')
|
||||||
|
|
||||||
RE_ISSUANCE = re.compile(r'''
|
RE_ISSUANCE = re.compile(r'''
|
||||||
^ ([A-Z]{4}\d+)
|
^ ([A-Z]{4}\d+)
|
||||||
\s+ (?P<wfo>[A-Z]{4})
|
\s+ (?P<wfo>[A-Z]{4})
|
||||||
\s+ (?P<day>\d{2}) (?P<hour>\d{2}) (?P<minute>\d{2})
|
\s+ (?P<day>\d{2}) (?P<hour>\d{2}) (?P<minute>\d{2})
|
||||||
''', re.X)
|
''', re.X)
|
||||||
|
|
31
lib/xmet/util.py
Normal file
31
lib/xmet/util.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import io
|
||||||
|
|
||||||
|
CHUNK_SIZE = 4096
|
||||||
|
CHUNK_STRIP = "\x01\x03\x0a\x20"
|
||||||
|
|
||||||
|
def each_chunk(fh: io.TextIOBase, sep: str, strip=None):
|
||||||
|
buf = ''
|
||||||
|
|
||||||
|
while True:
|
||||||
|
chunk = fh.read(CHUNK_SIZE)
|
||||||
|
|
||||||
|
if chunk == '':
|
||||||
|
ret = buf.strip(strip)
|
||||||
|
|
||||||
|
if ret != '':
|
||||||
|
yield ret
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
buf += chunk
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
part, buf = buf.split(sep, 1)
|
||||||
|
except ValueError:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
ret = part.strip(strip)
|
||||||
|
|
||||||
|
if ret != '':
|
||||||
|
yield ret
|
Loading…
Add table
Reference in a new issue