Skip to content

Commit

Permalink
Add yaml export (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv authored Mar 14, 2024
1 parent 1ffc869 commit 9e71f75
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 74 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BMLT Data Converter

- Converts BMLT data from JSON to CSV, XLSX or KML
- Converts BMLT data from JSON to CSV, XLSX KML, or YAML
- Note that export of KML is only supported with GetSearchResults.
- Use your semantic interface to build query url. You can find your semantic url by visiting the
[tally](https://tally.bmlt.app/) and hitting Explore on your root server.
Expand Down
148 changes: 78 additions & 70 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "8.56.0",
"@types/js-yaml": "^4.0.9",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"fetch-jsonp": "^1.3.0",
"gh-pages": "^6.1.1",
"js-yaml": "^4.1.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"sass": "^1.71.0",
Expand Down
12 changes: 9 additions & 3 deletions src/lib/DataConverter.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<script lang="ts">
import { writable } from 'svelte/store';
import { fetchData, exportCSV, exportXLSX, exportKML } from './DataUtils';
import { fetchData, exportCSV, exportXLSX, exportKML, exportYAML } from './DataUtils';
const processing = writable<boolean>(false);
const errorMessage = writable<string>('');
let query: string = '';
let csvDownloadUrl: string = '';
let xlsxDownloadUrl: string = '';
let kmlDownloadUrl: string = '';
let yamlDownloadUrl: string = '';
async function handleExport() {
if (query.trim() === '') return;
errorMessage.set('');
csvDownloadUrl = '';
xlsxDownloadUrl = '';
kmlDownloadUrl = '';
yamlDownloadUrl = '';
try {
processing.set(true);
const data = await fetchData(query);
csvDownloadUrl = exportCSV(data);
xlsxDownloadUrl = exportXLSX(data);
yamlDownloadUrl = exportYAML(data);
kmlDownloadUrl = query.includes('GetSearchResults') ? exportKML(data) : '';
} catch (error) {
errorMessage.set(error instanceof Error ? error.message : 'Failed to export data.');
Expand Down Expand Up @@ -50,9 +53,12 @@
<a href={xlsxDownloadUrl} class="download-links" download="BMLT_data.xlsx">Download XLSX</a><br />
{/if}
{#if kmlDownloadUrl}
<a href={kmlDownloadUrl} class="download-links" download="BMLT_data.kml">Download KML</a>
<a href={kmlDownloadUrl} class="download-links" download="BMLT_data.kml">Download KML</a><br />
{/if}
<div id="description">Converts BMLT data from JSON to CSV, XLSX or KML</div>
{#if yamlDownloadUrl}
<a href={yamlDownloadUrl} class="download-links" download="BMLT_data.yaml">Download YAML</a>
{/if}
<div id="description">Converts BMLT data from JSON to CSV, XLSX, KML or YAML</div>
</div>
<div id="footer">
<a href="https://github.com/bmlt-enabled/bmlt-data-converter/issues" class="footer-link" target="_blank">Issues?</a>
Expand Down
8 changes: 8 additions & 0 deletions src/lib/DataUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetchJsonp from 'fetch-jsonp';
import * as XLSX from 'xlsx';
import * as yaml from 'js-yaml';

interface Meeting {
meeting_name: string;
Expand Down Expand Up @@ -49,6 +50,13 @@ export function exportCSV(data: any[]): string {
return URL.createObjectURL(blob);
}

export function exportYAML(data: any[]): string {
const processedData = processExportData(data);
const yamlString = yaml.dump(processedData);
const blob = new Blob([yamlString], { type: 'application/x-yaml' });
return URL.createObjectURL(blob);
}

export function exportXLSX(data: any[]): string {
const processedData = processExportData(data);
const wb = XLSX.utils.book_new();
Expand Down

0 comments on commit 9e71f75

Please sign in to comment.