feat(config): make ArcGIS data source URLs configurable
- Add ARCGIS_CABLE_URL, ARCGIS_LANDING_POINT_URL, ARCGIS_CABLE_LANDING_RELATION_URL to config - Use @property to read URL from settings in collectors - URLs can now be configured via environment variables
This commit is contained in:
@@ -27,6 +27,10 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
CORS_ORIGINS: List[str] = ["http://localhost:3000", "http://localhost:8000"]
|
CORS_ORIGINS: List[str] = ["http://localhost:3000", "http://localhost:8000"]
|
||||||
|
|
||||||
|
ARCGIS_CABLE_URL: str = "https://services.arcgis.com/6DIQcwlPy8knb6sg/ArcGIS/rest/services/SubmarineCables/FeatureServer/2/query"
|
||||||
|
ARCGIS_LANDING_POINT_URL: str = "https://services.arcgis.com/6DIQcwlPy8knb6sg/ArcGIS/rest/services/SubmarineCables/FeatureServer/1/query"
|
||||||
|
ARCGIS_CABLE_LANDING_RELATION_URL: str = "https://services.arcgis.com/6DIQcwlPy8knb6sg/ArcGIS/rest/services/SubmarineCables/FeatureServer/3/query"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def REDIS_URL(self) -> str:
|
def REDIS_URL(self) -> str:
|
||||||
return os.getenv(
|
return os.getenv(
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from datetime import datetime
|
|||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from app.services.collectors.base import BaseCollector
|
from app.services.collectors.base import BaseCollector
|
||||||
|
from app.core.config import settings
|
||||||
|
|
||||||
|
|
||||||
class ArcGISCableCollector(BaseCollector):
|
class ArcGISCableCollector(BaseCollector):
|
||||||
@@ -18,7 +19,9 @@ class ArcGISCableCollector(BaseCollector):
|
|||||||
frequency_hours = 168
|
frequency_hours = 168
|
||||||
data_type = "submarine_cable"
|
data_type = "submarine_cable"
|
||||||
|
|
||||||
base_url = "https://services.arcgis.com/6DIQcwlPy8knb6sg/arcgis/rest/services/SubmarineCables/FeatureServer/2/query"
|
@property
|
||||||
|
def base_url(self) -> str:
|
||||||
|
return settings.ARCGIS_CABLE_URL
|
||||||
|
|
||||||
async def fetch(self) -> List[Dict[str, Any]]:
|
async def fetch(self) -> List[Dict[str, Any]]:
|
||||||
params = {"where": "1=1", "outFields": "*", "returnGeometry": "true", "f": "geojson"}
|
params = {"where": "1=1", "outFields": "*", "returnGeometry": "true", "f": "geojson"}
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
"""ArcGIS Landing Points Collector
|
|
||||||
|
|
||||||
Collects landing point data from ArcGIS GeoJSON API.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Dict, Any, List
|
from typing import Dict, Any, List
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import httpx
|
||||||
|
|
||||||
from app.services.collectors.base import BaseCollector
|
from app.services.collectors.base import BaseCollector
|
||||||
|
from app.core.config import settings
|
||||||
|
|
||||||
|
|
||||||
class ArcGISLandingPointCollector(BaseCollector):
|
class ArcGISLandingPointCollector(BaseCollector):
|
||||||
@@ -16,21 +13,18 @@ class ArcGISLandingPointCollector(BaseCollector):
|
|||||||
frequency_hours = 168
|
frequency_hours = 168
|
||||||
data_type = "landing_point"
|
data_type = "landing_point"
|
||||||
|
|
||||||
base_url = "https://services.arcgis.com/6DIQcwlPy8knb6sg/arcgis/rest/services/SubmarineCables/FeatureServer/1/query"
|
@property
|
||||||
|
def base_url(self) -> str:
|
||||||
|
return settings.ARCGIS_LANDING_POINT_URL
|
||||||
|
|
||||||
async def fetch(self) -> List[Dict[str, Any]]:
|
async def fetch(self) -> List[Dict[str, Any]]:
|
||||||
params = {"where": "1=1", "outFields": "*", "returnGeometry": "true", "f": "geojson"}
|
params = {"where": "1=1", "outFields": "*", "returnGeometry": "true", "f": "geojson"}
|
||||||
|
|
||||||
async with self._get_client() as client:
|
async with httpx.AsyncClient(timeout=60.0) as client:
|
||||||
response = await client.get(self.base_url, params=params)
|
response = await client.get(self.base_url, params=params)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return self.parse_response(response.json())
|
return self.parse_response(response.json())
|
||||||
|
|
||||||
def _get_client(self):
|
|
||||||
import httpx
|
|
||||||
|
|
||||||
return httpx.AsyncClient(timeout=60.0)
|
|
||||||
|
|
||||||
def parse_response(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
def parse_response(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
from typing import Dict, Any, List
|
from typing import Dict, Any, List
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import httpx
|
||||||
|
|
||||||
from app.services.collectors.base import BaseCollector
|
from app.services.collectors.base import BaseCollector
|
||||||
|
from app.core.config import settings
|
||||||
|
|
||||||
|
|
||||||
class ArcGISCableLandingRelationCollector(BaseCollector):
|
class ArcGISCableLandingRelationCollector(BaseCollector):
|
||||||
@@ -11,11 +13,11 @@ class ArcGISCableLandingRelationCollector(BaseCollector):
|
|||||||
frequency_hours = 168
|
frequency_hours = 168
|
||||||
data_type = "cable_landing_relation"
|
data_type = "cable_landing_relation"
|
||||||
|
|
||||||
base_url = "https://services.arcgis.com/6DIQcwlPy8knb6sg/arcgis/rest/services/SubmarineCables/FeatureServer/3/query"
|
@property
|
||||||
|
def base_url(self) -> str:
|
||||||
|
return settings.ARCGIS_CABLE_LANDING_RELATION_URL
|
||||||
|
|
||||||
async def fetch(self) -> List[Dict[str, Any]]:
|
async def fetch(self) -> List[Dict[str, Any]]:
|
||||||
import httpx
|
|
||||||
|
|
||||||
params = {"where": "1=1", "outFields": "*", "returnGeometry": "true", "f": "geojson"}
|
params = {"where": "1=1", "outFields": "*", "returnGeometry": "true", "f": "geojson"}
|
||||||
|
|
||||||
async with httpx.AsyncClient(timeout=60.0) as client:
|
async with httpx.AsyncClient(timeout=60.0) as client:
|
||||||
|
|||||||
Reference in New Issue
Block a user