Instantly share code, notes, and snippets.

@Sea-n /0 getData.sh Secret
Last active Oct 4, 2016

Embed
What would you like to do?
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