Information and tools to facilitate ethical consumption of goods and services.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.0 KiB

#!/bin/bash
# Syntax: gen_fi_table.sh <bank|brokerage|CU|insurer> [text]
#
# Add "text" option to write the tables in simple text and the legend in markdown.
# Without the text option, all output will be fully markdown.
#
# Lobbying data to incorporate in the future: https://disclosurespreview.house.gov/
typeset -r db_file=$(mktemp --dry-run --suffix=.db)
typeset -A sym=([red_circle]=$'\xF0\x9F\x94\xB4'
[green_circle]=$'\xf0\x9f\x9f\xa2'
[test_tube]=$'\xf0\x9f\xa7\xaa'
[cloud_lightening]=$'\xf0\x9f\x8c\xa9'
[detective]=$'\xf0\x9f\x95\xb5'
[okhand]=$'\xF0\x9F\x91\x8C'
[eye]=$'\xf0\x9f\x91\x81')
#local red_circle='🔴'
#local green_circle='🟢'
#local test_tube='🧪'
#local cloud_lightening='🌩'
#local detective='🕵'
#local okhand='👌'
#local eye='👁'
intro()
{
local lst=$1
local fi_kind=$2
case "$lst" in
white)
printf %s\\n 'The following '"${fi_kind}"'s have no significant ethical issues:'
;;
gray)
printf %s\\n 'These '"${fi_kind}"'s would normally be blacklisted, but due to the short whitelist they are set aside as a less evil compromise to those blacklisted. They should still be avoided if possible.'
;;
black)
printf %s\\n 'These '"${fi_kind}"'s have severe ethical or trust issues and should be boycotted:'
;;
esac
};#intro
table_populate()
{
# fiTbl: "financial institution table"
sqlite3 "${db_file}" < input_data/financial_institutions.sql
};#table_populate
table_text()
{
local fi_kind=$1
# .ft B (bold font)
# .ft I (italics font)
# .ft P (previous font)
# .ll 6i (6 inch width)
for lst in white gray black
do
if [[ "$lst" == black ]]
then
url_clause="''"
else
url_clause="case when url like '_%' then char(10)||'('||replace(url,'https://','')||')||||||' else '' end"
fi
printf %s "# ${lst^}"'list
```
.TS
box tab(|);
c|c|c|c|c|c|c.
.ft BI
'"$fi_kind"' | ALEC | Tor- | sensitive info | supported | forced drug | notes
| member | hostile | exposed to | CISPA | testing of |
| | | CloudFlare | | staff |
.ft P
.T&
l|l|l|l|l|l|lp40.
'
sqlite3 "${db_file}" "select substr(name,1,(select max(length(url)) from fiTbl where fi_kind = '$fi_kind')),
case when alec then 'y' else 'n' end,
case when antitor then 'y' else 'n' end,
case when cflogin then 'y' else 'n' end,
case when cispa then 'y' else 'n' end,
case when dt then 'y' else 'n' end,
case when notes is null then '' else 'T{
.ll 6i
'|| replace(replace(notes,'[',''),']',' ') ||'
T}' end||
$url_clause
from fiTbl where fi_kind = '$fi_kind' and lst_kind = '$lst'
order by name collate nocase;"
printf %s '.TE
```
'
done
}; #table_text
table_md()
{
local fi_kind=$1
printf %s\\n "# Directory of US-based ${fi_kind}s"
for lst in white gray black
do
if [[ "$lst" == black ]]
then
name_clause="'|'||name"
else
name_clause="case when url like '_%' then '|['||name||']('||url||')' else '|'||name end"
fi
printf %s "## ${lst^}list
$(intro $lst $fi_kind)"'
| *'"$fi_kind"'* | *ALEC member* | *Tor-hostile* | *sensitive info exposed to CloudFlare* | *supported CISPA* | *forced drug testing of staff* | *notes* |
|---|---|---|---|---|---|---|
'
sqlite3 "${db_file}" "select $name_clause,
case when alec then '${sym[okhand]}' else 'n' end,
case when antitor then '${sym[eye]}' else 'n' end,
case when cflogin then '${sym[cloud_lightening]}' else 'n' end,
case when cispa then '${sym[detective]}' else 'n' end,
case when dt then '${sym[test_tube]}' else 'n' end,
case when notes is null then '|' else notes||'|' end
from fiTbl where fi_kind = '$fi_kind' and lst_kind = '$lst'
order by name collate nocase;"
printf $'\n'
done
};#table_md
table_populate
case "$2" in
txt|text)
table_text "${1,,}" | tbl | nroff -Tascii | uniq
;;
*)
printf '%s\n\n' '[//]: # (** DO NOT EDIT this file directly! ** It is auto-generated. Changes should be made to financial_institutions.sql or '"${0##*/}"' instead.)'
table_md "${1,,}"; # the CLI arg must be one of: 'bank', 'brokerage', 'CU', or 'insurer'
;;
esac
cat input_data/table_legend.md