Skip to content

Commit

Permalink
Make following changes
Browse files Browse the repository at this point in the history
 - Refactor file save function to handle with a single filename for parameter
 - Add 'preview' key to paths dict
 - Simplify 'path exists' function
  • Loading branch information
plant99 committed Jul 22, 2020
1 parent 5a61a01 commit c1d29d1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions felicette/utils/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def check_sat_path(id):
os.mkdir(data_path)


def save_to_file(url, filename, id):
def save_to_file(url, filename, id, info_message):
data_path = os.path.join(workdir, id)
data_id = filename.split("-")[1].split(".")[0]
rprint("✗ required data doesn't exist, downloading", band_tag_map[data_id], "band")
data_id = filename.split("/")[-1].split("-")[1].split(".")[0]
rprint(info_message)
file_path = os.path.join(data_path, filename)
response = requests.get(url, stream=True)
with tqdm.wrapattr(
Expand All @@ -34,16 +34,15 @@ def save_to_file(url, filename, id):
fout.close()


def data_file_exists(filename, id):
data_path = os.path.join(workdir, id)
file_path = os.path.join(data_path, filename)
return os.path.exists(file_path)
def data_file_exists(filename):
return os.path.exists(filename)


def file_paths_wrt_id(id):
home_path_id = os.path.join(workdir, id)
return {
"base": home_path_id,
"preview": os.path.join(home_path_id, "%s-preview.jpg" % (id)),
"b4": os.path.join(home_path_id, "%s-b4.tiff" % (id)),
"b3": os.path.join(home_path_id, "%s-b3.tiff" % (id)),
"b2": os.path.join(home_path_id, "%s-b2.tiff" % (id)),
Expand Down

0 comments on commit c1d29d1

Please sign in to comment.