Rev 7644 | Blame | Compare with Previous | Last modification | View Log | RSS feed
from elixir import *from shop2020.model.v1.order.impl import DataServicefrom shop2020.model.v1.order.impl.DataService import Order, AmazonOrderfrom datetime import datetime, timedelta, date ,timeimport xlrdfrom shop2020.clients.TransactionClient import TransactionClientfrom shop2020.config.client.ConfigClient import ConfigClientconfig_client = ConfigClient()host = config_client.get_property('transaction_service_db_hostname')print "Selecting host: ",hostDataService.initialize(db_hostname=host)directory = "/tmp/Amazon-shipping.xls"amazonOrder = [[]]sheet = xlrd.open_workbook(directory)sh = sheet.sheet_by_index(0)def get_seconds(t_delta):return ((t_delta.microseconds + (t_delta.seconds + t_delta.days * 24 * 3600) * 10**6) / 10**6)for i in range (0,sh.nrows):amazonOrder.append([sh.cell_value(i,0),sh.cell_value(i,1),sh.cell_value(i,2)])for row in amazonOrder:if not len(row) == 0:amazonOrderCode = row[0]minDeliveryDate = row[1]maxDeliveryDate = row[2]print "=============================="print "OrderId",amazonOrderCodeprint "Minimum Delivery Date",minDeliveryDateprint "Maxmium Delivery Date",maxDeliveryDateprint "=============================="print "\n"print "Fetching OrderId's For Amazon Order Code"print "==============================="orders = AmazonOrder.query.filter(AmazonOrder.amazonOrderCode==amazonOrderCode).filter(AmazonOrder.status=='Order-Payment-Success').all()for order in orders:row = Order.query.filter(Order.id==order.orderId).first()if row is None:continueexpectedDeliveryTime = row.expected_delivery_timepromisedDeliveryTime = row.promised_delivery_timeexpectedShippingTime = row.expected_shipping_timepromisedShippingTime = row.promised_shipping_timedeltaTime = (expectedDeliveryTime-expectedShippingTime)print "+++++++++++++++++++++++"print "Expected Delivery Time : ",expectedDeliveryTimeprint "Promised Delivery Time : ",promisedDeliveryTimeprint "Expected Shipping Time : ",expectedShippingTimeprint "Promised Shipping Time : ",promisedShippingTimeprint "Delta Time : ", deltaTimeprint "=============================="newExpectedDeliveryTime=datetime.strptime(minDeliveryDate, "%d-%m-%Y")newTime = time(expectedDeliveryTime.hour, expectedDeliveryTime.minute, expectedDeliveryTime.second)newExpectedDeliveryTime = datetime.combine(newExpectedDeliveryTime, newTime)newPromisedDeliveryTime=datetime.strptime(minDeliveryDate, "%d-%m-%Y")newTime = time(promisedDeliveryTime.hour, promisedDeliveryTime.minute, promisedDeliveryTime.second)newPromisedDeliveryTime = datetime.combine(newPromisedDeliveryTime, newTime)newExpectedShippingTime=newExpectedDeliveryTime-deltaTimenewPromisedShippingTime=newPromisedDeliveryTime-deltaTimeprint "######################"print "New Expected Delivery Time : ",newExpectedDeliveryTimeprint "New Promised Delivery Time : ",newPromisedDeliveryTimeprint "New Expected Shipping Time : ",newExpectedShippingTimeprint "New Promised Shipping Time : ",newPromisedShippingTimeclient = TransactionClient().get_client()client.updateTimestampForAmazonOrder(order.orderId, get_seconds((newExpectedDeliveryTime-datetime(1970,1,1))-timedelta(hours = 5,minutes=30)), get_seconds((newPromisedDeliveryTime-datetime(1970,1,1))-timedelta(hours = 5,minutes=30)), get_seconds((newExpectedShippingTime-datetime(1970,1,1))-timedelta(hours = 5,minutes=30)), get_seconds((newPromisedShippingTime-datetime(1970,1,1))-timedelta(hours = 5,minutes=30)))