Rev 5866 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/pythonimport timeimport datetimeimport optparseimport sysimport csvimport xlrdimport tracebackif __name__ == '__main__' and __package__ is None:import ossys.path.insert(0, os.getcwd())from shop2020.clients.TransactionClient import TransactionClientfrom shop2020.clients.HelperClient import HelperClientfrom shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceExceptionfrom_user = 'help@saholic.com'from_pwd = '5h0p2o2o'to = ['rajveer.singh@shop2020.in']def create_emails(filename):print "Reading order list from:" + filenameworkbook = xlrd.open_workbook(filename)sheet = workbook.sheet_by_index(0)num_rows = sheet.nrowspicked_up_orders = {}txnClient = TransactionClient().get_client()for rownum in range(2, num_rows):order_id, product_name = sheet.row_values(rownum)[0:2]try:order = txnClient.getOrder(int(order_id))picked_up_orders[int(order_id)] = [str(product_name), order]subject = "Delay in delivery of your order " + str(order.id)body = "Dear " + order.customer_name + ",<br/><br/>Thanks for shopping at www.saholic.com.<br/><br/>In reference to your order ID " + str(order.id) + " for " + str(product_name) + " placed with us, we would like to inform you that due to some unforeseen circumstances at our warehouse, delivery would be delayed by a day or two.<br/><br/>We deeply regret the same.<br/><br/>Thanks & Regards<br/>Saholic Team "try:helper_client = HelperClient().get_client()helper_client.saveUserEmailForSending([order.customer_email], "", subject, body, str(order.id), "TransactionInfo", [], [])except Exception as e:print order.idexcept TransactionServiceException as tex:print tex.messageprint "Picked up Orders:"print picked_up_ordersdef main():parser = optparse.OptionParser()parser.add_option("-f", "--file", dest="filename",default="xxx.xls", type="string",help="The FILE this report is for",metavar="FILE")(options, args) = parser.parse_args()if len(args) != 0:parser.error("You've supplied extra arguments. Are you sure you want to run this program?")create_emails(options.filename)if __name__ == '__main__':main()