Compare commits
No commits in common. "2afcf59ba00d90a7aa0cbbeb4b4912b791c779b2" and "69e01d73e17efbfecc183528d7f5bcb24c199d3c" have entirely different histories.
2afcf59ba0
...
69e01d73e1
3 changed files with 24 additions and 33 deletions
|
@ -4,8 +4,30 @@ import argparse
|
|||
|
||||
from xmet.db import Database
|
||||
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'
|
||||
)
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
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