Blame | Last modification | View Log | RSS feed
#!/usr/bin/pythonimport optparseimport xlrd, xlwtimport random, stringfrom elixir import *from shop2020.model.v1.order.impl import DataServicefrom shop2020.model.v1.order.impl.DataService import HotspotStorefrom shop2020.utils import EmailAttachmentSenderfrom shop2020.utils.EmailAttachmentSender import get_attachment_partif __name__ == '__main__' and __package__ is None:import sysimport ossys.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.nrowsfor 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 = 1hs.name = namehs.email = emailhs.city = emailhs.circleId = circle_idhs.isActive = 1hs.collectedAmount = 0hs.availableLimit = limiths.creditLimit = limiths.password = ''.join(random.sample(string.digits,4))char_set = string.ascii_uppercase + string.digitshs.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_formatsheet.write(0, 0, "StoreCode", heading_xf)sheet.write(0, 1, "Salt", heading_xf)c = 1for 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 + 1fname = "/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.filenamecircle_id = options.circle_idlimit = options.limitif 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()