Skip to content

Commit

Permalink
Add paths in argparser for relative github action paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimjaved12 committed Jan 30, 2024
1 parent 632c5dc commit ffd940a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions ocw_oer_export/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,22 @@ def main():
default="api",
help="Specify data source for CSV creation (default: api)",
)

parser.add_argument(
"--input_path",
default="/private/output/ocw_api_data.json",
help="Output path for the CSV file",
)
parser.add_argument(
"--output_path",
default="/private/output/ocw_oer_export.csv",
help="Output path for the CSV file",
)
args = parser.parse_args()

if args.create_csv:
create_csv(source=args.source)
create_csv(
source=args.source, input_path=args.input_path, output_path=args.output_path
)
elif args.create_json:
create_json()
else:
Expand Down
4 changes: 2 additions & 2 deletions ocw_oer_export/create_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def transform_data(data):

def create_csv(
source="api",
input_file="/private/output/ocw_api_data.json",
input_path="/private/output/ocw_api_data.json",
output_path="/private/output/ocw_oer_export.csv",
):
"""
Expand All @@ -199,7 +199,7 @@ def create_csv(
api_data_json = extract_data_from_api(api_url=API_URL)

elif source == "json":
api_data_json = extract_data_from_json(input_file)
api_data_json = extract_data_from_json(input_path)

else:
raise ValueError("Invalid source. Use 'api' or 'json'.")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_csv_creation_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_csv_creation_from_json(self):
"""Test the CSV generated from JSON matches the expected CSV content."""
create_csv(
source="json",
input_file=self.sample_json_path,
input_path=self.sample_json_path,
output_path=self.generated_csv_path,
)
generated_csv_data = extract_data_from_file(self.generated_csv_path)
Expand Down

0 comments on commit ffd940a

Please sign in to comment.