summaryrefslogtreecommitdiff
path: root/daily_run.sh
blob: 94395cd1a15f6670a5037e1096684206cbbc1e5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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