Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

#!/usr/bin/python

import optparse
import xlrd, xlwt
import random, string
from elixir import *


from shop2020.model.v1.order.impl import DataService
from shop2020.model.v1.order.impl.DataService import HotspotStore

from shop2020.utils import EmailAttachmentSender
from shop2020.utils.EmailAttachmentSender import get_attachment_part



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





        

def upload_store_details(filename, circle_id, limit, db_hostname):
    DataService.initialize(dbname='transaction', db_hostname=db_hostname)

    
    workbook = xlrd.open_workbook(filename)
    sheet = workbook.sheet_by_index(0)
    l = []
    num_rows = sheet.nrows
    for rownum in range(1, num_rows):
        name = sheet.row_values(rownum)[0]
        code = sheet.row_values(rownum)[1]
        email = sheet.row_values(rownum)[2]
        
        hs = HotspotStore()
        hs.hotspotId = str(code)
        hs.companyId = 1
        hs.name = name
        hs.email = email
        hs.city = email
        hs.circleId = circle_id
        hs.isActive = 1
        hs.collectedAmount = 0
        hs.availableLimit  = limit
        hs.creditLimit = limit
        
        hs.password = ''.join(random.sample(string.digits,4))
        char_set = string.ascii_uppercase + string.digits
        hs.salt = ''.join(random.sample(char_set,25))
        l.append(hs)
    session.commit()



    wbk = xlwt.Workbook()
    sheet = wbk.add_sheet('main')

    heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
    
    excel_integer_format = '0'
    integer_style = xlwt.XFStyle()
    integer_style.num_format_str = excel_integer_format

    sheet.write(0, 0, "StoreCode", heading_xf)
    sheet.write(0, 1, "Salt", heading_xf)
    
    c = 1 
    for s in l:
        EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", [s.email], "Password for Recharge Dashboard", "Password of the recharge dashboard to be opened from OCR dashboard is " + s.password , [], [], ["rajveer.singh@shop2020.in"])
        print s.email, s.hotspotId, s.salt, str(s.password)
        sheet.write(c, 0, s.hotspotId)
        sheet.write(c, 1, s.salt)      
        c = c + 1
    fname = "/tmp/store-details.xls"
    wbk.save(fname)
    EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", ["deepak.chawla@spiceretail.co.in","rajveer.singh@shop2020.in"], "New Stores to be added", "Please find attached list of store along with salt.", [get_attachment_part(fname)], [], [])
    
    
def main():
    parser = optparse.OptionParser()
    parser.add_option("-f", "--file", dest="filename",
                   default="Store.xls", type="string",
                   help="Read the store date from FILE",
                   metavar="FILE")
    parser.add_option("-c", "--circle", dest="circle_id",
                      type="int", help="Load these entries for circle",
                      metavar="CIRCLE")
    parser.add_option("-l", "--limit", dest="limit",
                      type="int", help="The daily limit for a store",
                      metavar="TYPE")
    parser.add_option("-H", "--host", dest="hostname",
                      default="localhost",
                      type="string", help="The HOST where the DB server is running",
                      metavar="HOST")
    (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?")
    filename = options.filename
    circle_id = options.circle_id
    limit = options.limit
    if filename is None or circle_id is None or limit is None:
        parser.error("A circle's id and a filename must be provided. Use -h for usage details.")
    upload_store_details(filename, circle_id, type, options.hostname)

if __name__ == '__main__':
    main()