Subversion Repositories SmartDukaan

Rev

Rev 16130 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16130 Rev 16131
Line 15... Line 15...
15
                      type="string", help="The HOST where the mongo server is running",
15
                      type="string", help="The HOST where the mongo server is running",
16
                      metavar="mongo_host")
16
                      metavar="mongo_host")
17
 
17
 
18
(options, args) = parser.parse_args()
18
(options, args) = parser.parse_args()
19
 
19
 
-
 
20
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM"}
-
 
21
 
20
class __Items():
22
class __Items():
21
    
23
    
22
    def __init__(self, skuId, skuBundleId ,productName, source_id, rank):
24
    def __init__(self, skuId, skuBundleId ,productName, source_id, rank, url):
23
        self.skuId = skuId
25
        self.skuId = skuId
24
        self.skuBundleId = skuBundleId
26
        self.skuBundleId = skuBundleId
25
        self.productName = productName
27
        self.productName = productName
26
        self.source_id = source_id
28
        self.source_id = source_id
27
        self.rank = rank
29
        self.rank = rank
-
 
30
        self.url = url
28
        
31
        
29
    
32
    
30
 
33
 
31
def get_mongo_connection(host=options.mongoHost, port=27017):
34
def get_mongo_connection(host=options.mongoHost, port=27017):
32
    global con
35
    global con
Line 43... Line 46...
43
def checkItems():
46
def checkItems():
44
    global ITEMS
47
    global ITEMS
45
    negativeItems = get_mongo_connection().Catalog.NegativeDeals.find()
48
    negativeItems = get_mongo_connection().Catalog.NegativeDeals.find()
46
    for negativeItem in negativeItems:
49
    for negativeItem in negativeItems:
47
        masterItem = get_mongo_connection().Catalog.MasterData.find_one({'_id':negativeItem['sku']})
50
        masterItem = get_mongo_connection().Catalog.MasterData.find_one({'_id':negativeItem['sku']})
48
        item = __Items(masterItem.get('_id'), masterItem.get('skuBundleId') ,masterItem.get('product_name'),masterItem.get('source_id'),masterItem.get('rank'))
51
        item = __Items(masterItem.get('_id'), masterItem.get('skuBundleId') ,masterItem.get('product_name'),masterItem.get('source_id'),masterItem.get('rank'), \
-
 
52
                       masterItem.get('marketPlaceUrl'))
49
        ITEMS.append(item)
53
        ITEMS.append(item)
50
 
54
 
51
def sendMail():
55
def sendMail():
52
    message="""<html>
56
    message="""<html>
53
            <body>
57
            <body>
Line 56... Line 60...
56
            <thead>
60
            <thead>
57
            <tr><th>Item Id</th>
61
            <tr><th>Item Id</th>
58
            <th>Catalog Item Id</th>
62
            <th>Catalog Item Id</th>
59
            <th>Product Name</th>
63
            <th>Product Name</th>
60
            <th>Rank</th>
64
            <th>Rank</th>
-
 
65
            <th>Source</th>
-
 
66
            <th>Url</th>
61
            </tr></thead>
67
            </tr></thead>
62
            <tbody>"""
68
            <tbody>"""
63
    for item in ITEMS:
69
    for item in ITEMS:
64
        message+="""<tr>
70
        message+="""<tr>
65
        <td style="text-align:center">"""+str(item.skuId)+"""</td>
71
        <td style="text-align:center">"""+str(item.skuId)+"""</td>
66
        <td style="text-align:center">"""+str(item.skuBundleId)+"""</td>
72
        <td style="text-align:center">"""+str(item.skuBundleId)+"""</td>
67
        <td style="text-align:center">"""+(item.productName)+"""</td>
73
        <td style="text-align:center">"""+(item.productName)+"""</td>
68
        <td style="text-align:center">"""+str(item.rank)+"""</td>
74
        <td style="text-align:center">"""+str(item.rank)+"""</td>
-
 
75
        <td style="text-align:center">"""+str(getSourceForId(item.source_id))+"""</td>
-
 
76
        <td style="text-align:center">"""+str(item.url)+"""</td>
69
        </tr>"""
77
        </tr>"""
70
    message+="""</tbody></table></body></html>"""
78
    message+="""</tbody></table></body></html>"""
71
    print message
79
    print message
72
    msg = MIMEMultipart()
80
    msg = MIMEMultipart()
73
    msg['Subject'] = "Negative Items" + ' - ' + str(datetime.now())
81
    msg['Subject'] = "Negative Items" + ' - ' + str(datetime.now())
Line 83... Line 91...
83
    try:
91
    try:
84
        smtpServer.sendmail(sender, RECIPIENTS, msg.as_string())
92
        smtpServer.sendmail(sender, RECIPIENTS, msg.as_string())
85
        print "Successfully sent email"
93
        print "Successfully sent email"
86
    except:
94
    except:
87
        print "Error: unable to send email."
95
        print "Error: unable to send email."
-
 
96
 
-
 
97
def getSourceForId(source_id):
-
 
98
    if SOURCE_MAP.get(source_id) is not None:
-
 
99
        return SOURCE_MAP.get(source_id)
88
    
100
    else:
-
 
101
        return "Not valid source"
89
 
102
 
90
if __name__=='__main__':
103
if __name__=='__main__':
91
    checkItems()
104
    checkItems()
92
    sendMail()
105
    sendMail()
93
106