Skip to content

Instantly share code, notes, and snippets.

@Sea-n
Last active October 4, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sea-n/de1b0470fb6d6d2715091953bf1105cd to your computer and use it in GitHub Desktop.
Save Sea-n/de1b0470fb6d6d2715091953bf1105cd to your computer and use it in GitHub Desktop.
NTPC ESA Code
#!/bin/bash
id=${1:0:9}
declare -A sumTable=([A]=1 [B]=0 [C]=9 [D]=8 [E]=7 [F]=6 [G]=5 [H]=4 [I]=9 [J]=3 [K]=2 [L]=2 [M]=1 [N]=0 [O]=8 [P]=9 [Q]=8 [R]=7 [S]=6 [T]=5 [U]=4 [V]=3 [W]=1 [X]=3 [Z]=0)
if [[ $1 =~ ^[A-Z][0-9]{8}$ ]]; then
no0=${id:0:1}
no1=${id:1:0}
no2=${id:2:0}
no3=${id:3:0}
no4=${id:4:0}
no5=${id:5:0}
no6=${id:6:0}
no7=${id:7:0}
no8=${id:8:0}
sum=$((${sumTable[$no0]} + $no1*8 + $no2*7 + $no3*6 + $no4*5 + $no5*4 + $no6*3 + $no7*2 + $no8))
no9=$(((400 - $sum) % 10))
id=$id$no9
else
echo "FORMAT ERROR: $1" >&2
exit
fi
grep $id ad-data-${id:0:4} && (echo 'Data exist: $id'; exit)
curl "https://esa.ntpc.edu.tw/jsp/olreg/OlregAction.do?method=getAdData" \
-qd "idno=$id" \
|jq -r '.[0] |[.idno, .name, .birthday2] |@tsv'
> ad-data-${id:0:4}
[{"birthday":"1999/12/04","AD":"1","name":"莊皓翔","birthday1":"19991204","birthday2":"88/12/04","idno":"F123456789"}]
[
{
"birthday": "1999/12/04",
"AD": "1",
"name": "莊皓翔",
"birthday1": "19991204",
"birthday2": "88/12/04",
"idno": "F123456789"
}
]
F123456789 莊皓翔 88/12/04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment