Skip to content

Commit

Permalink
Updated to accecpt pathlib.PosixPath. Updated to return expected valu…
Browse files Browse the repository at this point in the history
…es for site only and site and class only.
  • Loading branch information
kenkehoe committed Mar 8, 2024
1 parent d425f44 commit 25e9409
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions act/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pathlib import Path
import re
import requests
from os import PathLike

spec = importlib.util.find_spec('pyart')
if spec is not None:
Expand Down Expand Up @@ -176,11 +177,10 @@ def __init__(self, ds=''):
The datastream or filename to parse
'''

if isinstance(ds, str):
if isinstance(ds, (str, PathLike)):
self.__datastream = Path(ds).name
else:
raise ValueError('Datastream or filename name must be a string')
raise ValueError('Datastream or filename name must be a string or pathlib.PosixPath.')

try:
self.__parse_datastream()
Expand Down Expand Up @@ -237,15 +237,17 @@ def __parse_datastream(self):
match = True

if not match:
m = re.search(r'(^[a-z]{3})(\w+)$', tempstring[0])
m = re.search(r'(^[a-z]{3})([^A-Z]+)$', tempstring[0])
if m is not None:
self.__site = m.group(1)
self.__class = m.group(2)
match = True

if not match and len(tempstring[0]) == 3:
self.__site = tempstring[0]
match = True
m = re.search(r'(^[a-z]{3})', tempstring[0])
if m is not None:
self.__site = m.group(1)
match = True

if not match:
raise ValueError(self.__datastream)
Expand Down

0 comments on commit 25e9409

Please sign in to comment.