Last active
May 2, 2016 03:00
-
-
Save crypticmind/88d951fb83cda6e963bdd7361e12e8a9 to your computer and use it in GitHub Desktop.
Read from MySQL (cmd. line), combine with HTTP JSON data (w/caching), output via template
This file contains hidden or 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
| [client] | |
| user=test_report | |
| password=test_report | |
| database=test_report | |
| raw | |
| batch | |
| skip-column-names |
This file contains hidden or 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
| #!/bin/bash | |
| USER=test_report | |
| DB=test_report | |
| PASSWORD=test_report | |
| # $1 = output file | |
| function append_query_as_markdown { | |
| IFS='' read -r -d '' Q | |
| /opt/local/lib/mysql56/bin/mysql --defaults-extra-file=db.cnf -e "$Q" | sed 's/|/\\|/g;s/ /|/g' >> $1 | |
| } | |
| # $1 = output file | |
| function append_query_as_csv { | |
| IFS='' read -r -d '' Q | |
| /opt/local/lib/mysql56/bin/mysql --defaults-extra-file=db.cnf -e "$Q" | sed 's/^/"/;s/$/"/;s/ /","/g' >> $1 | |
| } | |
| REPORT1=test_report.md | |
| cat > $REPORT1 <<REPORT | |
| # Test Report 1 | |
| A table. | |
| Column A | Column B | |
| ---------|--------- | |
| REPORT | |
| append_query_as_markdown $REPORT1 <<SQL | |
| SELECT a, b | |
| FROM test_data; | |
| SQL | |
| cat >> $REPORT1 <<REPORT | |
| End of report. | |
| REPORT | |
| REPORT2=test_report.csv | |
| cat > $REPORT2 <<REPORT | |
| "Column A", "Column B" | |
| REPORT | |
| append_query_as_csv $REPORT2 <<SQL | |
| SELECT a, b | |
| FROM test_data; | |
| SQL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment