forked from FrodeRennemo/VinmonopoletElastic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexData.sh
41 lines (30 loc) · 2.59 KB
/
indexData.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
#!/bin/bash
generate_post_data()
{
cat <<EOF
{"Datotid":\"$Datotid\","Varenummer":\"$Varenummer\","Varenavn":\"$Varenavn\","Volum":\"$Volum\","Pris":\"$Pris\","Literpris":\"$Literpris\","Varetype":\"$Varetype\","Produktutvalg":\"$Produktutvalg\","Butikkategori":\"$Butikkategori\","Fylde":\"$Fylde\","Friskhet":\"$Friskhet\","Garvestoffer":\"$Garvestoffer\","Bitterhet":\"$Bitterhet\","Sodme":\"$Sodme\","Farge":\"$Farge\","Lukt":\"$Lukt\","Smak":\"$Smak\","Passertil01":\"$Passertil01\","Passertil02":\"$Passertil02\","Passertil03":\"$Passertil03\","Land":\"$Land\","Distrikt":\"$Distrikt\","Underdistrikt":\"$Underdistrikt\","Argang":\"$Argang\","Rastoff":\"$Rastoff\","Metode":\"$Metode\","Alkohol":\"$Alkohol\","Sukker":\"$Sukker\",
"Syre":\"$Syre\","Lagringsgrad":\"$Lagringsgrad\","Produsent":\"$Produsent\","Grossist":\"$Grossist\","Distributor":\"$Distributor\","Emballasjetype":\"$Emballasjetype\","Korktype":\"$Korktype\","Vareurl":\"$Vareurl\"}
EOF
}
"$(mkdir download)"
curl='/usr/bin/curl'
http="https://www.vinmonopolet.no/medias/sys_master/products/products/hbc/hb0/8834253127710/produkter.csv"
curlargs="-f -s -S -k"
dot="$(cd "$(dirname "$0")"; pwd)"
path="$dot/download"
resp="$($curl $curlargs $http > $path/products.csv)"
#Set correct encoding
iconv -f ISO-8859-1 -t UTF-8 $path/products.csv > $path/iconproducts.csv
#Set mapping
mapping="$(cat mapping_fielddata.json)"
"$($curl -XPUT 'localhost:9200/_template/vinmonopolettpl?pretty' -H 'Content-Type: application/json' -d "$mapping")"
OLDIFS=$IFS
IFS=";"
declare -a fields=(Alkohol Pris Volum Bitterhet Literpris Sukker Syre)
#Datotid Varenummer Varenavn Volum Pris Literpris Varetype Produktutvalg Butikkategori Fylde Friskhet Garvestoffer Bitterhet Sodme Farge Lukt Smak Passertil01 Passertil02 Passertil03 Land Distrikt Underdistrikt Argang Rastoff Metode Alkohol Sukker Syre Lagringsgrad Produsent Grossist Distributor Emballasjetype Korktype Vareurl
while read Datotid Varenummer Varenavn Volum Pris Literpris Varetype Produktutvalg Butikkategori Fylde Friskhet Garvestoffer Bitterhet Sodme Farge Lukt Smak Passertil01 Passertil02 Passertil03 Land Distrikt Underdistrikt Argang Rastoff Metode Alkohol Sukker Syre Lagringsgrad Produsent Grossist Distributor Emballasjetype Korktype Vareurl
do
#replace "," with "."
curl -XPOST "localhost:9200/vinmonopolet/vinmonopolet?pretty" -H "Content-Type: application/json" -d "$(generate_post_data)"
done < $path/products.csv
IFS=$OLDIFS