Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
Make the following changes
Browse files Browse the repository at this point in the history
 - Refactor exit_cli to handle both print, and pprint
 - Show error if geocoding fails for a location's name
  • Loading branch information
plant99 committed Jul 26, 2020
1 parent 73324f2 commit df507be
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion felicette/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
def main(coordinates, location_name, pan_enhancement, preview_image, vegetation):
"""Satellite imagery for dummies."""
if not coordinates and not location_name:
exit_cli("Please specify either --coordinates or --location-name")
exit_cli(print, "Please specify either --coordinates or --location-name")
if location_name:
coordinates = geocoder_util(location_name)

Expand Down
5 changes: 3 additions & 2 deletions felicette/sat_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
def handle_prompt_response(response):
if response in ["n", "N"]:
exit_cli(
rprint,
"Why not try a different location next time? I'd suggest [link=https://en.wikipedia.org/wiki/Svalbard]Svalbard[/link] :)"
)
elif response in ["y", "Y", ""]:
return None
else:
exit_cli("[red]Sorry, invalid response. Exiting :([/red]")
exit_cli(rprint, "[red]Sorry, invalid response. Exiting :([/red]")


def search_landsat_data(coordinates, cloud_cover_lt):
Expand All @@ -37,7 +38,7 @@ def search_landsat_data(coordinates, cloud_cover_lt):

search_items = search.items()
if not len(search_items):
exit_cli("No data matched your search, please try different parameters.")
exit_cli(print, "No data matched your search, please try different parameters.")
landsat_item = search_items[0]
return landsat_item

Expand Down
5 changes: 4 additions & 1 deletion felicette/utils/geo_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import requests

from felicette.utils.sys_utils import exit_cli

def find_first_landsat(items):
for index, item in enumerate(items):
Expand All @@ -15,6 +15,9 @@ def geocoder_util(location_name):
)
)
r_json = r.json()
if len(r_json) == 0:
exit_cli(print, "Oops, couldn't geocode this location's name. Could you please try with coordinates(-c) option?")

# return lat, lon
return (float(r_json[0]["lon"]), float(r_json[0]["lat"]))

Expand Down
5 changes: 2 additions & 3 deletions felicette/utils/sys_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import sys
import os
from rich import print as rprint


def exit_cli(message):
rprint("%s" % message)
def exit_cli(print_func, message):
print_func("%s" % message)
sys.exit(0)


Expand Down

0 comments on commit df507be

Please sign in to comment.