Subversion Repositories SmartDukaan

Rev

Rev 2232 | Rev 2338 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/bin/bash

if [ $# -ne 1 ]
then
        echo "Usage: $0 <email>"
        exit  1
fi

EMAIL=$1

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

# Get standard environment variables
PRGDIR=`dirname $(readlink -f "$PRG")`
PYTHON_DIR=${PRGDIR}/../PyProj/src/shop2020/utils

DATE=`date +%Y-%b-%d`
mysql -uroot -pshop2020 user -e "SELECT u.email, u.communication_email, c.coupon_code, c.total_price, c.discounted_price FROM user u, cart c WHERE u.active_cart_id = c.id AND (c.coupon_code='SAHOLIC5' OR c.coupon_code='SAHOLIC1500' OR c.coupon_code='SAHOLIC500') ORDER BY c.coupon_code, u.email;" > /tmp/carts_with_coupon.${DATE}.csv
mysql -uroot -pshop2020 user -e "SELECT o.id AS order_id, u.email, u.communication_email, pt.coupon_code, pt.transaction_id, pt.applied_on FROM user.promotiontracker pt, user.user u, transaction.order o WHERE u.id = pt.user_id AND o.transaction_id = pt.transaction_id;" > /tmp/orders_with_coupon.${DATE}.csv

#Email the two report files.
python ${PYTHON_DIR}/EmailAttachmentSender.py -t ${EMAIL} -s "Daily Promotion Update - Carts" -a /tmp/carts_with_coupon.${DATE}.csv
python ${PYTHON_DIR}/EmailAttachmentSender.py -t ${EMAIL} -s "Daily Promotion Update - Orders" -a /tmp/orders_with_coupon.${DATE}.csv

rm /tmp/carts_with_coupon.${DATE}.csv
rm /tmp/orders_with_coupon.${DATE}.csv