Skip to content

Commit

Permalink
cove_rdls/process.py: Test for more content types
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed (ODSC) committed Aug 31, 2023
1 parent 9d8d503 commit dc4f2f1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cove_rdls/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from libcoveweb2.utils import get_file_type_for_flatten_tool
from libcoveweb2.utils import group_data_list_by

import logging
logger = logging.getLogger(__name__)

class Sample(ProcessDataTask):
def is_processing_applicable(self) -> bool:
Expand Down Expand Up @@ -53,7 +51,6 @@ def is_processing_needed(self) -> bool:
def _add_extention(self, supplied_data_file):
input_filename = supplied_data_file.upload_dir_and_filename()
filename = input_filename.split("/")[-1]
logger.debug(f"source_method: {supplied_data_file.source_method}, filename: {filename}")
if supplied_data_file.source_method == "url":
if "." not in filename:
content_type = magic.from_file(input_filename, mime=True)
Expand All @@ -62,13 +59,15 @@ def _add_extention(self, supplied_data_file):
file_renamed = f"{input_filename}.json"
elif content_type == 'text/csv':
file_renamed = f"{input_filename}.csv"
elif content_type == 'application/octet-stream':
elif (content_type == 'application/octet-stream' or content_type ==
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'):
file_renamed = f"{input_filename}.xlsx"
if file_renamed:
os.symlink(input_filename, file_renamed)
supplied_data_file.filename = file_renamed.split("/")[-1]
supplied_data_file.save()
raise Exception(f"add_extention - source_method: {supplied_data_file.source_method}, filename: {filename}, content_type: {content_type}, file_renamed: {file_renamed}")
# raise Exception(f"add_extention - source_method: {supplied_data_file.source_method}, ",
# f"filename: {filename}, content_type: {content_type}, file_renamed: {file_renamed}")

def process(self, process_data: dict) -> dict:
if self.supplied_data.format == "unknown":
Expand Down

0 comments on commit dc4f2f1

Please sign in to comment.