Subversion Repositories SmartDukaan

Rev

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

Rev 20172 Rev 20357
Line 3... Line 3...
3
import optparse
3
import optparse
4
import smtplib
4
import smtplib
5
from email.mime.text import MIMEText
5
from email.mime.text import MIMEText
6
from email.mime.multipart import MIMEMultipart
6
from email.mime.multipart import MIMEMultipart
7
import json
7
import json
-
 
8
import chardet
8
 
9
 
9
 
10
 
10
 
11
 
11
headers = {
12
headers = {
12
           'Browser-Name': 'Chrome',
13
           'Browser-Name': 'Chrome',
Line 25... Line 26...
25
 
26
 
26
bestSellers = []
27
bestSellers = []
27
now = datetime.now()
28
now = datetime.now()
28
exceptionList = []
29
exceptionList = []
29
 
30
 
30
 
-
 
-
 
31
xstr = lambda s: s or ""
31
 
32
 
32
class __RankInfo:
33
class __RankInfo:
33
    
34
    
34
    def __init__(self, identifier, rank, category, title, url):
35
    def __init__(self, identifier, rank, category, title, url):
35
        self.identifier = identifier
36
        self.identifier = identifier
Line 46... Line 47...
46
        url = "http://mobileapi.flipkart.net/3/discover/getSearch?store=tyy/4io&start=%d&count=10"%(i)
47
        url = "http://mobileapi.flipkart.net/3/discover/getSearch?store=tyy/4io&start=%d&count=10"%(i)
47
        print url
48
        print url
48
        response_data = fetchResponseUsingProxy(url, headers, livePricing=None, proxy=False, flipkart=False)
49
        response_data = fetchResponseUsingProxy(url, headers, livePricing=None, proxy=False, flipkart=False)
49
        input_json = json.loads(response_data)
50
        input_json = json.loads(response_data)
50
        for identifier, data in (input_json['RESPONSE']['product']).iteritems():
51
        for identifier, data in (input_json['RESPONSE']['product']).iteritems():
-
 
52
            t_title = data['value']['titles']['title']
51
            title = data['value']['titles']['title'] + " "+data['value']['titles']['subtitle']
53
            t_subtitle = data['value']['titles']['subtitle']
-
 
54
            title = (xstr(t_title) + " " + xstr(t_subtitle)).strip()
-
 
55
            print title
52
            url =  (data['value']['smartUrl']).replace("http://dl.flipkart.com/dl", "http://www.flipkart.com")
56
            url =  (data['value']['smartUrl']).replace("http://dl.flipkart.com/dl", "http://www.flipkart.com")
53
            r_info = __RankInfo(identifier, rank, 3, title, url)
57
            r_info = __RankInfo(identifier, rank, 3, title, url)
54
            bestSellers.append(r_info)
58
            bestSellers.append(r_info)
55
            rank = rank + 1
59
            rank = rank + 1
56
            
60
            
Line 62... Line 66...
62
        url = "http://mobileapi.flipkart.net/3/discover/getSearch?store=tyy/hry&start=%d&count=10"%(i)
66
        url = "http://mobileapi.flipkart.net/3/discover/getSearch?store=tyy/hry&start=%d&count=10"%(i)
63
        print url
67
        print url
64
        response_data = fetchResponseUsingProxy(url, headers, livePricing=None, proxy=False, flipkart=False)
68
        response_data = fetchResponseUsingProxy(url, headers, livePricing=None, proxy=False, flipkart=False)
65
        input_json = json.loads(response_data)
69
        input_json = json.loads(response_data)
66
        for identifier, data in (input_json['RESPONSE']['product']).iteritems():
70
        for identifier, data in (input_json['RESPONSE']['product']).iteritems():
-
 
71
            t_title = data['value']['titles']['title']
67
            title = data['value']['titles']['title'] + " "+data['value']['titles']['subtitle']
72
            t_subtitle = data['value']['titles']['subtitle']
-
 
73
            title = (xstr(t_title) + " " + xstr(t_subtitle)).strip()
-
 
74
            print title
68
            url =  (data['value']['smartUrl']).replace("http://dl.flipkart.com/dl", "http://www.flipkart.com")
75
            url =  (data['value']['smartUrl']).replace("http://dl.flipkart.com/dl", "http://www.flipkart.com")
69
            r_info = __RankInfo(identifier, rank, 5, title, url)
76
            r_info = __RankInfo(identifier, rank, 5, title, url)
70
            bestSellers.append(r_info)
77
            bestSellers.append(r_info)
71
            rank = rank + 1
78
            rank = rank + 1
72
 
79
 
Line 102... Line 109...
102
        <td style="text-align:center">"""+(CATEGORY_MAP.get(item.category))+"""</td>
109
        <td style="text-align:center">"""+(CATEGORY_MAP.get(item.category))+"""</td>
103
        <td style="text-align:center">"""+str(item.rank)+"""</td>
110
        <td style="text-align:center">"""+str(item.rank)+"""</td>
104
        <td style="text-align:center">"""+(item.url)+"""</td>
111
        <td style="text-align:center">"""+(item.url)+"""</td>
105
        </tr>"""
112
        </tr>"""
106
    message+="""</tbody></table></body></html>"""
113
    message+="""</tbody></table></body></html>"""
-
 
114
    encoding =  chardet.detect(message)
-
 
115
    try:
-
 
116
        message = message.decode(encoding.get('encoding'))
107
    print message
117
    except:
-
 
118
        message = message.decode(encoding.get('latin-1'))
108
    #recipients = ['kshitij.sood@saholic.com']
119
    #recipients = ['kshitij.sood@saholic.com']
109
    recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','ritesh.chauhan@saholic.com','khushal.bhatia@saholic.com']
120
    recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','ritesh.chauhan@saholic.com','khushal.bhatia@saholic.com']
110
    msg = MIMEMultipart()
121
    msg = MIMEMultipart()
111
    msg['Subject'] = "Flipkart Best Sellers" + ' - ' + str(datetime.now())
122
    msg['Subject'] = "Flipkart Best Sellers" + ' - ' + str(datetime.now())
112
    msg['From'] = ""
123
    msg['From'] = ""