Last active
June 17, 2018 18:22
-
-
Save HokieGeek/4b0479ded8ecc44997181b1e37eccce4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/awk -f | |
BEGIN { | |
vessels["other"]="0" | |
vessels["french press"]="1" | |
vessels["yixing"]="2" | |
vessels["tea-zer tumbler"]="3" | |
vessels["tea stick"]="4" | |
vessels["mesh spoon"]="5" | |
vessels["sauce pan"]="6" | |
vessels["cup"]="7" | |
vessels["bowl"]="8" | |
vessels["gaiwan"]="9" | |
vessels["steeper"]="10" | |
vessels["gaiwan2"]="11" | |
# 0=milk;1=cream;2=handh;3=sugar;4=brown;5=raw;6=honey;7=vanillae;8=vanillab;9=maplec;10=maples | |
fixins["milk"]="0" | |
fixins["cream"]="1" | |
fixins["handh"]="2" | |
fixins["sugar"]="3" | |
fixins["brown"]="4" | |
fixins["raw"]="5" | |
fixins["honey"]="6" | |
fixins["vanillae"]="7" | |
fixins["vanillab"]="8" | |
fixins["maplec"]="9" | |
fixins["maples"]="10" | |
fixins["chaigoop"]="11" | |
fixins["ice"]="12" | |
} | |
function getRating(line, START, FINISH) { | |
START=match(line, /\[/) | |
FINISH=match(line, /\]/) | |
return substr(line, START+1, FINISH-START-1) | |
} | |
function getTeaId(tea_name, ID_NAME, CMD) { | |
CMD=sprintf("./tid.sh \"%s\"", tolower(tea_name)) | |
CMD | getline ID_NAME | |
close(CMD) | |
if (length(ID_NAME) == 0) { | |
return tea_name | |
} | |
if (debug) { | |
return sprintf("%s {%s}", tea_name, ID_NAME) | |
} else { | |
return substr(ID_NAME, 0, match(ID_NAME, ":")-1) | |
} | |
} | |
function getSteepTime(line, START,FINISH,MIN,SEC,SEP) { | |
MIN="" | |
START=match(line, /[0-9]{1,2}m/) | |
if (START != 0) { | |
FINISH=match(substr(line, START), /m/) | |
MIN=substr(line, START, FINISH) | |
} | |
START=match(line, /[0-9]{1,2}s/) | |
if (START != 0) { | |
if (MIN != "") SEP=" " | |
FINISH=match(substr(line, START), /s/) | |
SEC=substr(line, START, FINISH) | |
} | |
return sprintf("%s%s%s", MIN, SEP, SEC) | |
} | |
function getComments(line, START,FINISH) { | |
START=match(line, /\(/) | |
FINISH=match(line, /\)/) | |
return substr(line, START+1, FINISH-START-1) | |
} | |
function getTemp(line, TEMP) { | |
if (match(line, / (at )*([0-9]{3})(deg)? /) != 0) { | |
return gensub(/^.* (at )*([0-9]{3})(deg)? .*$/, "\\2", 1, line) | |
} | |
return "" | |
} | |
function getVessel(line) { | |
if (line ~ /[Tt]umbler/ || line ~ /@work/) { | |
return vessels["tea-zer tumbler"] | |
} | |
if (line ~ /yixing/) { | |
return vessels["yixing"] | |
} | |
if (line ~ /gaiwan/) { | |
if (line ~ /gaiwan2/) { | |
return vessels["gaiwan2"] | |
} else { | |
return vessels["gaiwan"] | |
} | |
} | |
return vessels["steeper"] | |
} | |
function getFixins(line, FIXINS) { | |
if (line ~ /[Ll]ondon|[Ff]og/) { | |
return sprintf("%s;%s", fixins["milk"], fixins["vanillae"]) | |
} | |
if (line ~ /M\+BS/ || line ~ /milk \+ brn sgr/) { | |
FIXINS=sprintf("%s;%s;%s", FIXINS, fixins["milk"], fixins["brown"]) | |
} | |
if (line ~ /[Ss]ugar/) { | |
if (line ~ /[Bb]rown/) { | |
FIXINS=sprintf("%s;%s", FIXINS, fixins["brown"]) | |
} else { | |
FIXINS=sprintf("%s;%s", FIXINS, fixins["sugar"]) | |
} | |
} | |
if (line ~ /[Mm]ilk/) { | |
FIXINS=sprintf("%s;%s", FIXINS, fixins["milk"]) | |
} | |
if (line ~ /[Hh]oney/) { | |
FIXINS=sprintf("%s;%s", FIXINS, fixins["honey"]) | |
} | |
if (line ~ /chai goop/) { | |
FIXINS=sprintf("%s;%s", FIXINS, fixins["chaigoop"]) | |
} | |
if (line ~ /ice/) { | |
FIXINS=sprintf("%s;%s", FIXINS, fixins["ice"]) | |
} | |
sub(/^;/, "", FIXINS) | |
return FIXINS | |
} | |
function printEntry(year, date_time, tea_id, rating, comments, steep_time, vessel, temperature, session, fixins) { | |
# Timestamp,Date,Time,Tea,Rating,Comments,Pictures,Steep Time,Steeping Vessel,Steep Temperature,Session Instance,Fixins | |
## time | |
split(date_time, date_time_arr, "@") | |
fecha=sprintf("%d/%d/%d", substr(date_time_arr[1], 1, 2), substr(date_time_arr[1], 3, 2), year) | |
time=date_time_arr[2] | |
printf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", | |
strftime("%D %T"), | |
fecha, | |
time, | |
tea_id, | |
rating, | |
comments, | |
"", | |
steep_time, | |
vessel, | |
temperature, | |
session, | |
fixins) | |
} | |
NR == 1 { | |
year=$1 | |
next | |
} | |
{ | |
date_time=1 | |
} | |
$1 == "-" { | |
tea_id="" | |
name="" | |
for (i=2; i < NF; i++) { | |
if (match($i, /@/) != 0) { | |
date_time=i | |
fflush() | |
break | |
} | |
name=sprintf("%s %s", name, $i) | |
} | |
sub(/^[ \t]*/, "", name) | |
if (tolower(name) ~ /london fog/) { | |
name="Earl Grey" | |
} else if (tolower(name) ~ /anxi.*tgy/ || tolower(name) ~ /anxi oolong/) { | |
name="High-roasted Anxi Tie Guan Yin" | |
} else if (tolower(name) ~ /red robe/) { | |
name="Wuyi Medium-Roasted Da Hong Pao Rock Tea" | |
} else if (tolower(name) ~ /fernwood/) { | |
name="Flavia Earl Grey" | |
} | |
tea_id=getTeaId(name) | |
if (tolower(name) ~ /harishpur cl/ || tolower(name) ~ /harishpur broken/) { | |
tea_id=27 | |
} else if (tolower(name) ~ /japanese sencha/) { | |
tea_id=37 | |
} else if (tolower(name) ~ /2006 mengku/) { | |
tea_id=117 | |
} else if (tolower(name) ~ /mengku 2006 wild arbor/) { | |
tea_id=125 | |
} else if (tolower(name) ~ /curls/) { | |
tea_id=70 | |
} else if (tolower(name) == "lumbini large leaf") { | |
tea_id=99 | |
} else if (tolower(name) == "phoenix dragon pearls") { | |
tea_id=102 | |
} else if (tolower(name) == "lapsang souchong imperial") { | |
tea_id=73 | |
} else if (tolower(name) == "birchall great rift") { | |
tea_id=170 | |
} else if (tolower(name) == "birchall virunga earl grey") { | |
tea_id=171 | |
} else if (tolower(name) == "mengku organic") { | |
tea_id=182 | |
} else if (tolower(name) == "sichuan gongfu") { | |
tea_id=130 | |
} else if (tolower(name) == "yunnan pu erh gold") { | |
tea_id=69 | |
} | |
cmd=sprintf("echo '%s-%s' | md5sum | awk '{ print $1 }'", $date_time, name) | |
cmd | getline session | |
close(cmd) | |
} | |
{ | |
printEntry(year, | |
$date_time, | |
tea_id, | |
getRating($0), | |
getComments($0), | |
getSteepTime($0), | |
getVessel($0), | |
getTemp($0), | |
session, | |
getFixins($0)) | |
} |
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
curl -o teadb.tsv 'https://docs.google.com/spreadsheets/d/1-U45bMxRE4_n3hKRkTPTWHTkVKC8O3zcSmkjEyYFYOo/pub?output=tsv' |
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/sh | |
awk -F'\t' -v param="$1" ' | |
tolower($4) ~ param && $19 == "TRUE" { printf("%d: %s\n", $3, $4) } | |
' teadb.tsv | |
# tolower($4) ~ param && $20 == "TRUE" { printf("%d: %s\n", $3, $4) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment