Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7204 rajveer 1
#!/usr/bin/python
2
 
3
import optparse
4
import xlrd, xlwt
5
import random, string
6
from elixir import *
7
 
8
 
9
from shop2020.model.v1.order.impl import DataService
10
from shop2020.model.v1.order.impl.DataService import HotspotStore
11
 
12
from shop2020.utils import EmailAttachmentSender
13
from shop2020.utils.EmailAttachmentSender import get_attachment_part
14
 
15
 
16
 
17
if __name__ == '__main__' and __package__ is None:
18
    import sys
19
    import os
20
    sys.path.insert(0, os.getcwd())
21
 
22
 
23
 
24
 
25
 
26
 
27
 
28
def upload_store_details(filename, circle_id, limit, db_hostname):
29
    DataService.initialize(dbname='transaction', db_hostname=db_hostname)
30
 
31
 
32
    workbook = xlrd.open_workbook(filename)
33
    sheet = workbook.sheet_by_index(0)
34
    l = []
35
    num_rows = sheet.nrows
36
    for rownum in range(1, num_rows):
37
        name = sheet.row_values(rownum)[0]
38
        code = sheet.row_values(rownum)[1]
39
        email = sheet.row_values(rownum)[2]
40
 
41
        hs = HotspotStore()
42
        hs.hotspotId = str(code)
43
        hs.companyId = 1
44
        hs.name = name
45
        hs.email = email
46
        hs.city = email
47
        hs.circleId = circle_id
48
        hs.isActive = 1
49
        hs.collectedAmount = 0
50
        hs.availableLimit  = limit
51
        hs.creditLimit = limit
52
 
53
        hs.password = ''.join(random.sample(string.digits,4))
54
        char_set = string.ascii_uppercase + string.digits
55
        hs.salt = ''.join(random.sample(char_set,25))
56
        l.append(hs)
57
    session.commit()
58
 
59
 
60
 
61
    wbk = xlwt.Workbook()
62
    sheet = wbk.add_sheet('main')
63
 
64
    heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
65
 
66
    excel_integer_format = '0'
67
    integer_style = xlwt.XFStyle()
68
    integer_style.num_format_str = excel_integer_format
69
 
70
    sheet.write(0, 0, "StoreCode", heading_xf)
71
    sheet.write(0, 1, "Salt", heading_xf)
72
 
73
    c = 1 
74
    for s in l:
75
        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"])
76
        print s.email, s.hotspotId, s.salt, str(s.password)
77
        sheet.write(c, 0, s.hotspotId)
78
        sheet.write(c, 1, s.salt)      
79
        c = c + 1
80
    fname = "/tmp/store-details.xls"
81
    wbk.save(fname)
82
    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)], [], [])
83
 
84
 
85
def main():
86
    parser = optparse.OptionParser()
87
    parser.add_option("-f", "--file", dest="filename",
88
                   default="Store.xls", type="string",
89
                   help="Read the store date from FILE",
90
                   metavar="FILE")
91
    parser.add_option("-c", "--circle", dest="circle_id",
92
                      type="int", help="Load these entries for circle",
93
                      metavar="CIRCLE")
94
    parser.add_option("-l", "--limit", dest="limit",
95
                      type="int", help="The daily limit for a store",
96
                      metavar="TYPE")
97
    parser.add_option("-H", "--host", dest="hostname",
98
                      default="localhost",
99
                      type="string", help="The HOST where the DB server is running",
100
                      metavar="HOST")
101
    (options, args) = parser.parse_args()
102
    if len(args) != 0:
103
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
104
    filename = options.filename
105
    circle_id = options.circle_id
106
    limit = options.limit
107
    if filename is None or circle_id is None or limit is None:
108
        parser.error("A circle's id and a filename must be provided. Use -h for usage details.")
109
    upload_store_details(filename, circle_id, type, options.hostname)
110
 
111
if __name__ == '__main__':
112
    main()