Subversion Repositories SmartDukaan

Rev

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

Rev 4039 Rev 4198
Line 32... Line 32...
32
        for brand in self.brands:
32
        for brand in self.brands:
33
            if full_name.startswith(brand):  return (brand, full_name.replace(brand, '').strip())
33
            if full_name.startswith(brand):  return (brand, full_name.replace(brand, '').strip())
34
        
34
        
35
        return ("", full_name)
35
        return ("", full_name)
36
 
36
 
-
 
37
def getURLSource(url):
-
 
38
    try:
-
 
39
        return str(url.split('.')[1].strip())
-
 
40
    except Exception:
-
 
41
        return None
-
 
42
 
37
def isValidRule(rule):
43
def isValidRule(rule):
38
    try:
44
    try:
39
        if rule is None:
45
        if rule is None:
40
            return False
46
            return False
41
        
47
        
Line 74... Line 80...
74
    '''
80
    '''
75
    Receives a list of products (returned from search results) &
81
    Receives a list of products (returned from search results) &
76
    returns a clustered dictionary, where products are grouped by
82
    returns a clustered dictionary, where products are grouped by
77
    the 'source'
83
    the 'source'
78
    '''
84
    '''
79
    clustered_results = {'flipkart': [], 'homeshop18': [], 'infibeam': [], 'letsbuy': []}
85
    clustered_results = {'adexmart': [], 'flipkart': [], 'homeshop18': [], 'infibeam': [], 'letsbuy': []}
80
    
86
    
81
    for product in products:
87
    for product in products:
82
        clustered_results[product['source']].append(product)
88
        clustered_results[product['source']].append(product)
83
    
89
    
84
    return clustered_results
90
    return clustered_results
Line 90... Line 96...
90
        filtered_cluster[source] = getItemsWithTopScore(products)
96
        filtered_cluster[source] = getItemsWithTopScore(products)
91
    
97
    
92
    return filtered_cluster
98
    return filtered_cluster
93
 
99
 
94
def removePriceFormatting(price_string):
100
def removePriceFormatting(price_string):
95
    return price_string.replace('Rs.', '').replace(',', '').strip()
101
    return price_string.replace('Rs.', '').replace('Rs', '').replace(',', '').replace(' ', '').strip().split('.')[0]
96
    
102
    
-
 
103
def getSearchURL(source, name):
-
 
104
        
-
 
105
        search_urls = {
-
 
106
            'flipkart': 'http://www.flipkart.com/search-mobiles?query=$$&from=all&searchGroup=mobiles',
-
 
107
            'homeshop18': 'http://www.homeshop18.com/$$/search:$$/categoryid:3024',
-
 
108
            'adexmart': 'http://adexmart.com/search.php?orderby=position&orderway=desc&search_query=$$',
-
 
109
            'infibeam': 'http://www.infibeam.com/Mobiles/search?q=$$',
-
 
110
            'letsbuy': 'http://www.letsbuy.com/advanced_search_result.php?cPath=254&keywords=$$'
-
 
111
        }
-
 
112
        return search_urls[source].replace('$$', name)
-
 
113
 
97
def getDisplayInfo(filtered_cluster):
114
def getDisplayInfo(filtered_cluster, product_name):
98
    display_info = {'flipkart': {}, 'homeshop18': {}, 'infibeam': {}, 'letsbuy': {}}
115
    display_info = {'adexmart': {}, 'flipkart': {}, 'homeshop18': {}, 'infibeam': {}, 'letsbuy': {}}
99
    
116
    
100
    for source, products in filtered_cluster.iteritems():
117
    for source, products in filtered_cluster.iteritems():
101
        
118
        
102
        if len(products) > 0:
119
        if len(products) > 0:
103
            if isPriceSame(products):
120
            if isPriceSame(products):
Line 112... Line 129...
112
                display_info[source]['url'] = None
129
                display_info[source]['url'] = None
113
                display_info[source]['text'] = 'Conflict'
130
                display_info[source]['text'] = 'Conflict'
114
        else:
131
        else:
115
            display_info[source]['price'] = None
132
            display_info[source]['price'] = None
116
            display_info[source]['data'] = None
133
            display_info[source]['data'] = None
117
            display_info[source]['url'] = None
134
            display_info[source]['url'] = getSearchURL(source, product_name)
118
            display_info[source]['text'] = 'Not Found'
135
            display_info[source]['text'] = 'Not Found'
119
    
136
    
120
    return display_info
137
    return display_info
121
 
138
 
122
def getSynonyms():
139
def getSynonyms():
123
    file_path = '/tmp/synonyms.json'
140
    file_path = '/tmp/price-comp-dashboard/synonyms.json'
124
    file = open(file_path, 'r')
141
    file = open(file_path, 'r')
125
    synonyms_json = file.read()
142
    synonyms_json = file.read()
126
 
143
 
127
    synonyms = {}
144
    synonyms = {}
128
    for key, value in json.loads(synonyms_json).iteritems():
145
    for key, value in json.loads(synonyms_json).iteritems():