Advertisement
Guest User

dfdfdfdf

a guest
Sep 20th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # How to run this script
  4. #
  5. # Windows only, do it first:
  6. # vagrant up
  7. # vagrant ssh
  8. # cd /vagrant
  9. #
  10. # Running the script:
  11. # chmod +x scriptCSV.sh
  12. # ./scriptCSV.sh
  13. #
  14. # If you want put the output in one file run:
  15. # ./scriptCSV.sh > logs.txt
  16. #
  17.  
  18. printf '\n\n*** Create specific folder ***'
  19. mkdir scriptCSVExecution
  20. cd scriptCSVExecution
  21.  
  22. printf '\n\n*** Variables ***'
  23. ROOT_DIR=$(pwd)
  24. DATE=$(date +%Y%m%d)
  25. NODE_SCRIPT_DIR='luxysale-nodeutils'
  26. TMP_DIR='/tmp/luxysale/csv'
  27. CLEAR_DIR=true #clear the scriptCSV directory before begin the work
  28.  
  29. #CSV Models, use the pattern NAME*, URL*, USER, PASSWORD. (*)Mantadory fields
  30. ESCADA=(
  31.      'escada'
  32.     'http://datafeed.api.productserve.com/datafeed/download/apikey/9eddbff4488e7d71d64d210b1b9dc1f4/language/en/cid/97,98,142,144,146,129,595,539,147,149,613,626,135,159,169,161,170,137,171,548,174,178,179,175,172,623,139,614,189,194,141,205,198,206,203,208,199,204,201/bid/64751/columns/aw_deep_link,product_name,aw_product_id,merchant_product_id,merchant_image_url,description,merchant_category,search_price,merchant_name,aw_image_url,currency,delivery_cost,merchant_deep_link,language,rrp_price,brand_name,colour,specifications,keywords,product_type,is_for_sale,Fashion%3Asuitable_for,Fashion%3Acategory,Fashion%3Asize,Fashion%3Amaterial/format/csv/delimiter/%2C/compression/gzip/adultcontent/1/'
  33. )
  34. MONNIER=(
  35.     'monnier'
  36.     'http://datatransfer.cj.com/datatransfer/files/4756211/outgoing/productcatalog/190452/Monnier_Frères_UK-Product_Catalog.txt.gz'
  37.     'USER_XXXXX'
  38.     'PASS_XXXXX'
  39. )
  40. ZIP_FILES=(
  41.   ESCADA[@]
  42.   MONNIER[@]
  43. )
  44.  
  45. echo 'ROOT_DIRE='$ROOT_DIR
  46. echo 'DATE='$DATE
  47. echo 'NODE_SCRIPT_DIR='$NODE_SCRIPT_DIR
  48. echo 'TMP_DIR='$TMP_DIR
  49. echo 'CLEAR_DIR='$CLEAR_DIR
  50.  
  51.  
  52. printf '\n\n*** Preparing the directory ***'
  53. if [ "$CLEAR_DIR" = true ] ; then
  54.     rm -rf *
  55. fi
  56.  
  57. mkdir -p unzipedFolder # -p => Create dir if not exist
  58. cd unzipedFolder
  59. rm -rf *
  60. cd ..
  61.  
  62. mkdir -p $TMP_DIR
  63.  
  64.  
  65. for ZIP_FILE  in "${ZIP_FILES[@]}"
  66. do
  67.   MODEL_NAME=${!ZIP_FILE:0:1}
  68.   URL=${!ZIP_FILE:1:1}
  69.   USER=${!ZIP_FILE:2:1}
  70.   PASSWORD=${!ZIP_FILE:3:1}
  71.  
  72.  
  73.   printf '\n\n*** Downloading the zip ***'
  74.   if [ -z "$USER" ]; then
  75.     wget $URL -O $MODEL_NAME.gz
  76.   else
  77.     wget --user $USER --password $PASSWORD $URL -O $MODEL_NAME.gz
  78.   fi
  79.  
  80.  
  81.   printf '\n\n*** Unzipping ***'
  82.   gunzip $MODEL_NAME.gz
  83.   mv $MODEL_NAME unzipedFolder/$MODEL_NAME$DATE_origin.csv
  84.  
  85.  
  86.   printf '\n\n*** Invoking nodeuitls script to format the csv ***'
  87.   if [ ! -d "$NODE_SCRIPT_DIR" ]; then
  88.     yes | git clone -b master https://levymore@bitbucket.org/luxysale-nodeutils.git
  89.     cd $NODE_SCRIPT_DIR
  90.     npm install
  91.     cd ..
  92.   fi
  93.   node $NODE_SCRIPT_DIR/transform-csv.js $MODEL_NAME unzipedFolder/$MODEL_NAME$DATE_origin.csv
  94.  
  95.  
  96.   printf '\n\n*** Moving the csv into /tmp/luxysale/csv/escada<ddMMYYYY>.csv ***'
  97.   cp dist/escada-converted1.csv $TMP_DIR/$MODEL_NAME$DATE.csv
  98. done
  99.  
  100.  
  101. printf '\n\n*** Listing /tmp/luxysale/csv/ files ***\n'
  102. ls $TMP_DIR
  103.  
  104. printf '\n\n*** Finished !!! ***'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement