forked from decidim/decidim.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_cities.bash
executable file
·66 lines (60 loc) · 2.02 KB
/
export_cities.bash
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
#!/bin/bash
#
# Generator for decidim.org (data/cities.yml)
#
# Input CSV with this structure:
# organization,type,status,company,notes,contact,country,url,image,repo,slug,tags,order
# "Ajuntament de Barcelona",,,,,,,,"https://www.decidim.barcelona/","/images/partners/logo_partner_ajbcn.jpg",,,,,
#
# Output example:
# - barcelona
# - name: Barcelona
# - url: https://www.decidim.barcelona/
# - image: /images/partners/logo_partner_ajbcn.jpg
# - helsinki
# (...)
slugify () {
# https://stackoverflow.com/a/49035906
echo "$1" | iconv -t ascii//TRANSLIT | sed -r s/[~\^]+//g | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z
}
INPUT='data.csv'
OLDIFS=$IFS
IFS=,
# we need to order the data by column 13 (order)
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
[ $# -eq 0 ] && { echo "No arguments supplied. Pass 'cities' or 'monitor'"; exit 99; }
ORD_INPUT=/tmp/data.csv
sort -n -t"," -k12 $INPUT > $ORD_INPUT
if [ $1 == "monitor" ] ; then
OUTPUT=tmp/cities.ex
else
OUTPUT=data/cities.yml
fi
echo "# This is an autogenerated file." > $OUTPUT
echo "# If you want your installation to be on decidim.org," >> $OUTPUT
echo "# you can create us an issue on https://github/decidim/decidim.org" >> $OUTPUT
echo "# or say hi at hola [at] decidim.org" >> $OUTPUT
echo "" >> $OUTPUT
while read organization type status company notes contact country url image repo slug tags order
do
if [ $1 == "monitor" ] ; then
if ( [ $status == "Producción" ] || [ $status == "Pre-producción" ] ) && [ ! -z $url ] ; then
slug=$(slugify $organization)
echo " \"$slug\" => %{
name: \"$name\",
url: \"$url\",
tags: $tags,
repo: \"$repo\"
}," >> $OUTPUT
fi
else
if [ $status == "Producción" ] && [ ! -z $url ] && [ ! -z $image ] ; then
slug=$(slugify $organization)
echo "- ${slug}:" >> $OUTPUT
echo " name: ${organization}" >> $OUTPUT
echo " url: ${url}" >> $OUTPUT
echo " image: ${image}" >> $OUTPUT
fi
fi
done < $ORD_INPUT
IFS=$OLDIFS