Skip to content

Commit

Permalink
untested code ❗️ - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Jul 16, 2024
1 parent 3178ca2 commit da8f888
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 10 deletions.
2 changes: 1 addition & 1 deletion blue_geo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

DESCRIPTION = f"{ICON} AI for precise geospatial data analysis and visualization."

VERSION = "4.46.1"
VERSION = "4.47.1"

REPO_NAME = "blue-geo"

Expand Down
40 changes: 37 additions & 3 deletions blue_geo/firms/api/area/__main__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
import argparse
from datetime import datetime, timedelta
from blue_geo import VERSION
from blue_geo.firms.api.area import NAME
from blue_geo.ukraine_timemap.functions import ingest
from blue_geo.firms.api.area.enums import Area, Source
from blue_geo.firms.api.area.classes import APIRequest
from blue_geo.logger import logger
from blueness.argparse.generic import sys_exit

parser = argparse.ArgumentParser(NAME, description=f"{NAME}-{VERSION}")
parser.add_argument(
"task",
type=str,
help="get_url",
help="ingest",
)
parser.add_argument(
"--object_name",
type=str,
)
parser.add_argument(
"--source",
type=str,
default=Source.default.name,
help="|".join(Source.default.values),
)
parser.add_argument(
"--area",
type=str,
default=Area.default.name,
help="|".join(Area.default.values),
)
parser.add_argument(
"--date",
type=str,
default=(datetime.now() - timedelta(days=5)).strftime("%Y-%m-%d"),
help="yyyy-mm-dd",
)
parser.add_argument(
"--day_range",
type=int,
default=1,
help="1..10",
)

args = parser.parse_args()

success = False
if args.task == "ingest":
success, _ = ingest(object_name=args.object_name)
api_request = APIRequest(
area=Area[args.area],
source=Source[args.source],
day_range=args.day_range,
date=args.date,
)

success = api_request.ingest(object_name=args.object_name)
else:
success = None

Expand Down
11 changes: 7 additions & 4 deletions blue_geo/firms/api/area/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
class APIRequest:
def __init__(
self,
source: Source = Source.MODIS_NRT,
area: Area = Area.WORLD,
source: Source = Source.default,
area: Area = Area.default,
date: str = "",
day_range: int = 1,
log: bool = True,
Expand All @@ -20,8 +20,6 @@ def __init__(
self.area: Area = area
self.source: Source = source

assert day_range >= 1
assert day_range <= 10
self.day_range: int = day_range

self.date: str = (
Expand All @@ -40,6 +38,11 @@ def as_str(self) -> str:
self.source.description,
)

def ingest(object_name: str) -> bool:
logger.info(f"🪄 -> {object_name}")

return True

def url(self, html: bool = False) -> str:
return "{}/api/area/{}/{}/{}/{}/{}/{}".format(
self.prefix,
Expand Down
16 changes: 16 additions & 0 deletions blue_geo/firms/api/area/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ class Area(Enum):
WEST = auto()
WORLD = auto()

@property
def default():
return Area.WORLD

@property
def values():
return [area.name.lower() for area in Area]


class Source(Enum):
LANDSAT_NRT = (
Expand Down Expand Up @@ -41,3 +49,11 @@ class Source(Enum):

def __init__(self, _, description):
self.description = description

@property
def default():
return Source.MODIS_NRT

@property
def values():
return [source.name for source in Source]
9 changes: 7 additions & 2 deletions blue_geo/tests/test_firms_api_area.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import pytest
from blue_geo.firms.api.area import enums
from abcli.modules.objects import unique_object
from blue_geo.firms.api.area.classes import APIRequest


@pytest.mark.parametrize(
["area", "source"],
[
[
enums.Area.WORLD,
enums.Source.MODIS_NRT,
enums.Area.default,
enums.Source.default,
],
],
)
def test_blue_geo_firms_api_area(
area: enums.Area,
source: enums.Source,
):
object_name = unique_object()

api_request = APIRequest(area=area, source=source)

assert api_request.as_str()

assert api_request.url()

assert api_request.url(html=True)

assert api_request.ingest(object_name)

0 comments on commit da8f888

Please sign in to comment.