Subversion Repositories SmartDukaan

Rev

Rev 16267 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/python

'''
This script sends the daily report to bluedart

@author : Rajveer
'''
import optparse
import sys
import datetime


if __name__ == '__main__' and __package__ is None:
    import os
    sys.path.insert(0, os.getcwd())

from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
warehouses = {}
warehouses[0] = 'KalkaJI'
warehouses[5] = 'KalkaJI'
warehouses[3] = 'Gurgaon'
warehouses[4] = 'Ghaziabad'
warehouses[9] = 'KalkaJI'
warehouses[7] = 'Mahipalpur'
warehouses[12] = 'Goregaon'
warehouses[13] = 'Bhiwandi'
warehouses[3298] = 'Hyderabad'
warehouses[1765] = 'Bangalore'
    
to_addresses = {} 
to_addresses[1] = ["ajays@bluedart.com","arunsingh@bluedart.com","PraveenKumar@bluedart.com","ADhiran.EXCHNET@bluedart.com",
                "DarpanS@bluedart.com","BijuS@bluedart.com","VijayK@bluedart.com","SonikaP@bluedart.com",
                "sandeep.sachdeva@shop2020.in","sunil.kumar@shop2020.in"]
to_addresses[3] = ["dispatch@delhivery.com", "rajaram.gupta@delhivery.com","sandeep.sachdeva@shop2020.in","sunil.kumar@shop2020.in"] 
to_addresses[6] = ["sandeep.sachdeva@shop2020.in","sunil.kumar@shop2020.in", 'bookings@getsetred.net', 'arvind.chauhan@getsetred.net', 'okaops@getsetred.net'] 
from_user = "cnc.center@shop2020.in"
from_pwd = "5h0p2o2o"

def send_report(providerId):
    filenames = []
    for warehouseId in warehouses.keys():
        today = datetime.date.today()
        datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
        
        subject = "Saholic: Soft Data - All Warehouses - Date:" + datestr
        text = "Find attached file for All Warehouses pickup data" 
        
        filename = "/CourierDetailReports/courier-details-" + "cod" + "-" + str(warehouseId) + "-" + str(providerId) + "-" + datestr + ".xls";
        print filename
        if os.path.exists(filename):
            filenames.append(filename)
            
        filename = "/CourierDetailReports/courier-details-" + "prepaid" + "-" + str(warehouseId) + "-" + str(providerId) + "-" + datestr + ".xls";
        print filename
        if os.path.exists(filename):
            filenames.append(filename)
    mail(from_user, from_pwd, to_addresses[providerId], subject, text, [get_attachment_part(filename) for filename in filenames])
    
    
def main():
    '''
    parser = optparse.OptionParser()
    parser.add_option("-p", "--provider", dest="provider",
                   default="1", type="int",
                   help="The PROVIDER this alert is for",
                   metavar="PROVIDER")
    parser.add_option("-t", "--type", dest="type",
                   default="Prepaid", type="string",
                   help="TYPE of AWB nos. to track",
                   metavar="TYPE")
    parser.add_option("-T", "--threshold", dest="threshold",
                   default="200", type="int",
                   help="The THRESHOLD below which the alert should be raised",
                   metavar="THRESHOLD")
    (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?")
    '''
    
     
    for i in (1,3,6):
        send_report(i)

if __name__ == '__main__':
    main()