-
Notifications
You must be signed in to change notification settings - Fork 13
/
run_all.sh
executable file
·108 lines (84 loc) · 2.15 KB
/
run_all.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
# Runs through all the SVG/PDF files available for download
# Help and usage
help () {
cat << EOF
written by Data Science Campus <datasciencecampus@ons.gov.uk>
run_all.sh [COMMAND] DATE [STATES]
Commands
full - run both the extraction and summary
summary - run just the summary
help - prints this help text
Date format: yyyy-mm-dd (Note: passing a date is mandatory at the moment)
STATES - by passing \`true\` as the value for STATES, it will run on
US states instead.
e.g. 1. run_all.sh full 2020-04-05 # runs all countries for that period
2. run_all.sh full 2020-04-05 true # runs all US states for that date
EOF
exit 0
}
# Default mode run both full and summary
MODE=ALL
# Set mode if full/summary passed
case $1 in
full)
MODE=FULL
DATE=$2
STATES=$3
;;
summary)
MODE=SUMMARY
DATE=$2
STATES=$3
;;
help)
help
;;
*)
DATE=$1
STATES=$2
;;
esac
set -e # Exit on any error
# Get dates lookup
CLEAN=$(echo $DATE | sed -E 's/\-/_/g')
DATES_FILE="config/dates_lookup_${CLEAN}.csv"
echo "Using $DATES_FILE as lookup"
# List all the countries/states
case $STATES in
true)
COUNTRIES=$(./mobius.py svg | sed -En "s/.*[0-9 \.]+([US-]{2}(\-[A-Z][A-Za-z_]+)).*$DATE.*/\1/p")
;;
*)
COUNTRIES=$(./mobius.py svg | sed -En "s/.*[0-9 \.]+([A-Z]{2}(\-[A-Z][A-Za-z_]+)?).*$DATE.*/\1/p")
;;
esac
COUNTRIES=($COUNTRIES)
full () {
./mobius.py full pdfs/"${1}_${DATE}".pdf svgs/"${1}_${DATE}".svg output $DATES_FILE
}
summary () {
./mobius.py summary pdfs/"${1}_${DATE}".pdf output $DATES_FILE
}
for COUNTRY in "${COUNTRIES[@]}"
do
echo Running for $COUNTRY $DATE
# Download pdf and svg
./mobius.py download $COUNTRY $DATE
case $MODE in
ALL)
echo "Running summary and full"
full $COUNTRY
summary $COUNTRY
;;
SUMMARY)
echo "Running summary only"
summary $COUNTRY
;;
FULL)
echo "Running full only"
full $COUNTRY
;;
esac
done
echo "Script finished."