|
1 | 1 | import requests |
2 | | - |
3 | | -from api.api_types import Opportunity, OpportunityCollection, Search |
| 2 | +from api.models import Opportunity |
4 | 3 |
|
5 | 4 | BLACKSKY_BASE_URL = "https://api.dev.blacksky.com/v1" |
6 | 5 |
|
7 | 6 |
|
8 | | -def stac_search_to_oppurtunities_request(search_request: Search): |
| 7 | +def stat_to_oppurtunities_request(search_request: Opportunity): |
9 | 8 | """ |
10 | 9 | :param search_request: STAC search as passed on to find_future_items |
11 | 10 | :return: a triple of iw request body, geom and bbox (geom and bbox needed again later to construct STAC answers) |
@@ -55,37 +54,33 @@ def get_oppurtunities(blacksky_request, token): |
55 | 54 | return r.json()["opportunities"] |
56 | 55 |
|
57 | 56 |
|
58 | | -def oppurtunity_to_stac_item(iw): |
| 57 | +def blacksky_oppurtunity_to_opportunity(iw): |
59 | 58 | """ |
60 | 59 | translates a Planet Imaging Windows into a STAC item |
61 | 60 | :param iw: an element from the 'imaging_windows' array of a /imaging_windows/[search_id] response |
62 | 61 | :return: a corresponding STAC item |
63 | 62 | """ |
64 | 63 |
|
65 | | - item = Opportunity( |
| 64 | + opportunity = Opportunity( |
66 | 65 | id=iw["satellite"], |
| 66 | + product_id="BS-Test:Standard", |
67 | 67 | geometry={"type": "Point", "coordinates": [iw["longitude"], iw["latitude"], 0]}, |
68 | | - properties={ |
69 | | - "title": "", |
70 | | - "datetime": f"{iw['timestamp']}/{iw['timestamp']}", |
71 | | - "constraints": { |
72 | | - "off_nadir": iw["offNadirAngleDegrees"], |
73 | | - "cloud_cover": iw["weatherForecast"]["cloudCover"], |
74 | | - }, |
| 68 | + datetime=f"{iw['timestamp']}/{iw['timestamp']}", |
| 69 | + constraints={ |
| 70 | + "off_nadir": iw["offNadirAngleDegrees"], |
| 71 | + "cloud_cover": iw["weatherForecast"]["cloudCover"], |
75 | 72 | }, |
76 | 73 | ) |
77 | 74 |
|
78 | | - return item |
| 75 | + return opportunity |
79 | 76 |
|
80 | 77 |
|
81 | 78 | class BlackskyBackend: |
82 | 79 | async def find_opportunities( |
83 | 80 | self, |
84 | | - search_request: Search, |
| 81 | + search_request: Opportunity, |
85 | 82 | token: str, |
86 | | - ) -> OpportunityCollection: |
87 | | - blacksky_request = stac_search_to_oppurtunities_request(search_request) |
| 83 | + ) -> list[Opportunity]: |
| 84 | + blacksky_request = stat_to_oppurtunities_request(search_request) |
88 | 85 | oppurtunities = get_oppurtunities(blacksky_request, token) |
89 | | - stac_items = [oppurtunity_to_stac_item(iw) for iw in oppurtunities] |
90 | | - |
91 | | - return OpportunityCollection(features=stac_items, links=[]) |
| 86 | + return [blacksky_oppurtunity_to_opportunity(iw) for iw in oppurtunities] |
0 commit comments