Created
September 20, 2016 17:24
-
-
Save levymoreira/1171cd93284595d703d27912867164f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# How to run this script | |
# | |
# Windows only, do it first: | |
# vagrant up | |
# vagrant ssh | |
# cd /vagrant | |
# | |
# Running the script: | |
# chmod +x scriptCSV.sh | |
# ./scriptCSV.sh | |
# | |
# If you want put the output in one file run: | |
# ./scriptCSV.sh > logs.txt | |
# | |
printf '\n\n*** Create specific folder ***' | |
mkdir scriptCSVExecution | |
cd scriptCSVExecution | |
printf '\n\n*** Variables ***' | |
ROOT_DIR=$(pwd) | |
DATE=$(date +%Y%m%d) | |
NODE_SCRIPT_DIR='luxysale-nodeutils' | |
TMP_DIR='/tmp/luxysale/csv' | |
CLEAR_DIR=true #clear the scriptCSV directory before begin the work | |
#CSV Models, use the pattern NAME*, URL*, USER, PASSWORD. (*)Mantadory fields | |
ESCADA=( | |
'escada' | |
'http://datafeed.api.productserve.com/datafeed/download/apikey/9eddb' | |
) | |
MONNIER=( | |
'monnier' | |
'http://datatransfer.cj.com/datatransfer/files/4756211/outgoing/productcatalog' | |
'USER_XX' | |
'PASS_XX' | |
) | |
ZIP_FILES=( | |
ESCADA[@] | |
MONNIER[@] | |
) | |
echo 'ROOT_DIRE='$ROOT_DIR | |
echo 'DATE='$DATE | |
echo 'NODE_SCRIPT_DIR='$NODE_SCRIPT_DIR | |
echo 'TMP_DIR='$TMP_DIR | |
echo 'CLEAR_DIR='$CLEAR_DIR | |
printf '\n\n*** Preparing the directory ***' | |
if [ "$CLEAR_DIR" = true ] ; then | |
rm -rf * | |
fi | |
mkdir -p unzipedFolder # -p => Create dir if not exist | |
cd unzipedFolder | |
rm -rf * | |
cd .. | |
mkdir -p $TMP_DIR | |
for ZIP_FILE in "${ZIP_FILES[@]}" | |
do | |
MODEL_NAME=${!ZIP_FILE:0:1} | |
URL=${!ZIP_FILE:1:1} | |
USER=${!ZIP_FILE:2:1} | |
PASSWORD=${!ZIP_FILE:3:1} | |
printf '\n\n*** Downloading the zip ***' | |
if [ -z "$USER" ]; then | |
wget $URL -O $MODEL_NAME.gz | |
else | |
wget --user $USER --password $PASSWORD $URL -O $MODEL_NAME.gz | |
fi | |
printf '\n\n*** Unzipping ***' | |
gunzip $MODEL_NAME.gz | |
mv $MODEL_NAME unzipedFolder/$MODEL_NAME$DATE_origin.csv | |
printf '\n\n*** Invoking nodeuitls script to format the csv ***' | |
if [ ! -d "$NODE_SCRIPT_DIR" ]; then | |
yes | git clone -b master https://levymore:[email protected]/ssfernando/luxysale-nodeutils.git | |
cd $NODE_SCRIPT_DIR | |
npm install | |
cd .. | |
fi | |
node $NODE_SCRIPT_DIR/transform-csv.js $MODEL_NAME unzipedFolder/$MODEL_NAME$DATE_origin.csv | |
printf '\n\n*** Moving the csv into /tmp/luxysale/csv/escada<ddMMYYYY>.csv ***' | |
cp dist/escada-converted1.csv $TMP_DIR/$MODEL_NAME$DATE.csv | |
done | |
printf '\n\n*** Listing /tmp/luxysale/csv/ files ***\n' | |
ls $TMP_DIR | |
printf '\n\n*** Finished !!! ***' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment