bdambola / BD

Collection of scripts and misc info
0 stars 0 forks source link

Script to detect symbol status and move to correct state if required #3

Open bdambola opened 8 years ago

bdambola commented 8 years ago

This is a script written in python that detects the current status of an exchange symbol and moves it to the correct state if necessary. It works in conjunction with a shell based script.

bdambola commented 8 years ago
# Import required modules here:
import os
import commands
import subprocess
import datetime

os.system("clear")
#Getting current date
today = datetime.date.today()
prev = datetime.date.today()-datetime.timedelta(1)
#Formatting date for products 
product_date = today.strftime('%Y-%m-%d')
prev_product_date = prev.strftime('%Y-%m-%d')

#Checking if products have the current business date
current_product_date = commands.getoutput('python /usr/sbin/ops-scripts/piCheck.py -o amzn | grep -o ' + product_date + ' | wc -l ' )
current_product_state = commands.getoutput('python /usr/sbin/ops-scripts/piCheck.py -o amzn | grep -o OPEN | wc -l ' )  
eod_product_state = commands.getoutput('python /usr/sbin/ops-scripts/piCheck.py -o amzn | grep -o END_OF_DAY | wc -l ' )
sod_product_state = commands.getoutput('python /usr/sbin/ops-scripts/piCheck.py -o amzn | grep -o START_OF_DAY | wc -l ' )
open_product_state = commands.getoutput('python /usr/sbin/ops-scripts/piCheck.py -o amzn | grep -o OPEN | wc -l ' )
previous_product_date = commands.getoutput('python /usr/sbin/ops-scripts/piCheck.py -o amzn | grep -o ' + prev_product_date + ' | wc -l ' )
#Saving the results
results = int(current_product_date) + int(current_product_state)
eod_results = int(eod_product_state)
sod_results = int(sod_product_state)
open_results = int(previous_product_date) + int(open_product_state)
#Reporting results and taking action if required
if (results == 2 ):
    print 'Product state and date correct. No action required'
elif (eod_results == 1 ):
    commands.getoutput('/home/dambre/scripts/python/MAT/eodRotate.sh ')
elif (sod_results == 1 ):
    commands.getoutput('/home/dambre/scripts/python/MAT/sodRotate.sh ')
elif (open_results == 2 ):
    commands.getoutput('/home/dambre/scripts/python/MAT/openRotate.sh ') 
#else:
 #   print 'Product state and date correct. No action required' 
bdambola commented 8 years ago
/opt/gts/sbin/changeProductState.py --log-file=/tmp/tmp_$USER\_changeProductState.log --use-current-business-date --target-product-state=END_OF_DAY --ofi-user=xxx --ofi-password=nomatter --ofi-host=tc-oat01 --db-host=tc-oat02 --only-active-products
sleep 10
/opt/gts/sbin/changeProductState.py --log-file=/tmp/tmp_$USER\_changeProductState.log --use-current-business-date --target-product-state=POST_END_OF_DAY --ofi-user=xxx --ofi-password=nomatter --ofi-host=tc-oat01 --db-host=tc-oat02 --only-active-products
sleep 10
/opt/gts/sbin/changeProductState.py --log-file=/tmp/tmp_$USER\_changeProductState.log --business-date=`date +'%Y-%m-%d'` --target-product-state=START_OF_DAY --ofi-user=xxx --ofi-password=nomatter --ofi-host=tc-oat01 --db-host=tc-oat02--only-active-products
sleep 10
/opt/gts/sbin/changeProductState.py --log-file=/tmp/tmp_$USER\_changeProductState.log --business-date=`date +'%Y-%m-%d'` --target-product-state=OPEN --ofi-user=xxx --ofi-password=nomatter --ofi-host=tc-oat01 --db-host=tc-oat02 --only-active-products