diff options
| author | Nathan Kinkade <nkinkade@creativecommons.org> | 2014-05-19 18:18:52 -0400 |
|---|---|---|
| committer | Nathan Kinkade <nkinkade@creativecommons.org> | 2014-05-19 18:18:52 -0400 |
| commit | fea92fb73fc066701a4e5e578edee7d737045a41 (patch) | |
| tree | 8475a74fb159756896e90a802eca32e2545ed86d /daily_run.sh | |
| parent | 03a01ac31a16cf7f44e827db15b7483b0ec330cd (diff) | |
| parent | c1ea47789989b08e919645d8b8133cfea0ad97c9 (diff) | |
Diffstat (limited to 'daily_run.sh')
| -rwxr-xr-x | daily_run.sh | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/daily_run.sh b/daily_run.sh new file mode 100755 index 0000000..94395cd --- /dev/null +++ b/daily_run.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# This date is just for display. Since this script will get run at 10pm UTC +# and we are in Eastern Time, set the date as yesterday. +DATE=$(TZ=America/New_York date +'%A, %B %d, %Y, %l:%M%p') + +# Get the highest current court_case_no from the database +YEAR=$(date +'%y') +PASSWD=$(cat ../../mysql_passwd) +QUERY="SELECT court_case_no FROM cases WHERE court_case_no LIKE 'f-$YEAR-%' ORDER BY court_case_no DESC LIMIT 250" +CASE_NOS=$(mysql -u root -p$PASSWD -ss -e "$QUERY" mdcc) + +# Turn list into an array +cases=($CASE_NOS) + +MAX_CASE_NO="${cases[0]}" + +# Here we go back over the latest cases to fill in gaps, since the case numbers +# are not always entered sequentially on any given day. +idx=1 +shift +for case in ${cases[@]} +do + SEQ_PAD=${case:5} + SEQ=$(echo $SEQ_PAD | sed 's/^0*//') + if [[ ! -z ${cases[$idx]} ]] + then + NEXT_SEQ_PAD=${cases[$idx]:5} + NEXT_SEQ=$(echo $NEXT_SEQ_PAD | sed 's/^0*//') + if [ $NEXT_SEQ != $((SEQ-1)) ] + then + let "gap = SEQ - NEXT_SEQ" + let "GAP_START = NEXT_SEQ + 1" + let "GAP_STOP = SEQ - 1" + ./miami_dade_clerk_courts.py $GAP_START $GAP_STOP $YEAR + fi + let "idx = idx + 1" + fi +done + +CASE_SEQ_PAD=${MAX_CASE_NO:5} + +# The case number in the database has leading zeros. Strip them off. +START=$(echo $CASE_SEQ_PAD | sed 's/^0*//') + +# Fetch all the latest entries +./miami_dade_clerk_courts.py $START 0 $YEAR + +# Get the new highest court_case_no after fetching all the latest +QUERY="SELECT court_case_no FROM cases WHERE court_case_no LIKE 'f-$YEAR-%' ORDER BY court_case_no DESC LIMIT 1" +NEW_CASE_NO=$(mysql -u root -p$PASSWD -ss -e "$QUERY" mdcc) + +# Send a link with the results to some people +RCPT_TO="udighe@gmail.com jinita.thakkar@gmail.com" +SUBJECT="MDCC daily run for $DATE" +BODY="http://dighelaw.com/mdcc/search.php?between=$MAX_CASE_NO:$NEW_CASE_NO" +echo $BODY | mail -s "$SUBJECT" $RCPT_TO |
