fix: syntax? #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Convert CSV to JSON for Database updates | |
on: | |
push: | |
paths: | |
- 'db/**' | |
pull_request: | |
paths: | |
- 'db/**' | |
jobs: | |
convert: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout project | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install pandas | |
run: pip install pandas | |
- name: Convert CSV to JSON | |
run: | | |
python -c "import os; import pandas as pd; import regex as re;\ | |
def transform_objectid(text):\ | |
return re.sub(r'ObjectId\\((.*?)\\)', r'{\"$oid\": \"\\1\"}', text);\ | |
os.makedirs('db/json', exist_ok=True);\ | |
csv_files = [f for f in os.listdir('db/csv') if f.endswith('.csv')];\ | |
for file in csv_files:\ | |
df = pd.read_csv(f'db/csv/{file}');\ | |
for column in df.select_dtypes(include=['object']):\ | |
df[column] = df[column].apply(lambda x: transform_objectid(str(x)) if x else x);\ | |
json_path = 'db/json/' + file.replace('.csv', '.json');\ | |
df.to_json(json_path, orient='records', lines=True);" | |
- name: Upload JSON files as artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: json-files | |
path: db/json/ |