-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjs-generator.sh
40 lines (34 loc) · 1.36 KB
/
js-generator.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
#!/bin/bash
# Validate dependencies
command git >/dev/null 2>/dev/null;
if [ $? -eq 127 ]; then
echo "You need to install git to use this. Aborting.";
exit 1;
fi
# Fetch the CSV
rm -rf European-Parliament-Open-Data
git clone https://github.com/eliflab/European-Parliament-Open-Data.git
# Generate the JS file
csv=$(tail -n +2 European-Parliament-Open-Data/meps_full_list_with_twitter_accounts.csv);
countries=$(echo "$csv"|cut -d, -f4|sort -u);
version=$(grep refs/remotes/origin/master European-Parliament-Open-Data/.git/packed-refs|cut -d" " -f1);
echo "/*";
echo " * MEPsOnTwitter: a list of MEPs, by country, and their twitter accounts.";
echo " * Automaticly generated by https://github.com/marado/MEPsOnTwitter";
echo " * Source data from https://github.com/eliflab/European-Parliament-Open-Data";
echo " (revision: $version)";
echo " * Data license: http://opendatacommons.org/licenses/odbl/1.0/";
echo " */";
echo "$countries" | while read -r country; do
# Since we have deployed previously, I want to maintain retro-compatibility
# with older versions, by remaping some countrycodes. Also, white spaces
# must begone.
countrycode="$(echo "$country"|sed 's/\ //g'|sed 's/UnitedKingdom/UK/g')";
echo "var MEPs$countrycode = [";
meps=$(echo "$csv"|grep "$country,"|cut -d, -f3|grep -v ^$);
for mep in $meps; do
echo "\"${mep/@/}\",";
done;
echo "];";
echo "";
done