From aabe93dc0b50b2b087d7cf47c0df70fd8aec535d Mon Sep 17 00:00:00 2001 From: shoulinwei Date: Fri, 3 Jan 2025 09:38:04 +0800 Subject: [PATCH] get header --- csst_dfs_client/__init__.py | 8 +++++++- tests/test_common.py | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/csst_dfs_client/__init__.py b/csst_dfs_client/__init__.py index bb4883c..fd6c6d4 100644 --- a/csst_dfs_client/__init__.py +++ b/csst_dfs_client/__init__.py @@ -44,4 +44,10 @@ def read_file(file_path: str) -> BytesIO: iobytes_io.seek(0) except OSError: raise AppError("Failed to read file.") - return iobytes_io \ No newline at end of file + return iobytes_io + +def get_free_header(file_path: str) -> dict: + result = request.get(f"/api/common/header?file_path={file_path}") + if result.success: + return result.data + raise AppError("Failed to get free header. Reason: " + result.message) \ No newline at end of file diff --git a/tests/test_common.py b/tests/test_common.py index f7c3b72..fcb5cc9 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -1,6 +1,6 @@ import unittest import os -from csst_dfs_client import download_file, read_file +from csst_dfs_client import download_file, read_file, get_free_header class CommonTestCase(unittest.TestCase): def setUp(self): @@ -33,4 +33,8 @@ class CommonTestCase(unittest.TestCase): assert os.path.exists(tmp_file_path) os.remove(tmp_file_path) + + def test_get_free_header(self): + header_items = get_free_header(file_path= "L0/MSC/routine/SCI/10109100157991/CSST_MSC_MS_SCI_20240609181116_20240609181347_10109100157991_27_L0_V01.fits") + print(header_items) \ No newline at end of file -- GitLab