Subversion Repositories SmartDukaan

Rev

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

Rev 3350 Rev 3453
Line 9... Line 9...
9
if cmd_folder not in sys.path:
9
if cmd_folder not in sys.path:
10
    sys.path.insert(0, cmd_folder)
10
    sys.path.insert(0, cmd_folder)
11
 
11
 
12
from shop2020.clients.CatalogClient import CatalogClient
12
from shop2020.clients.CatalogClient import CatalogClient
13
 
13
 
-
 
14
CHARACTER_ENCODING = 'ISO-8859-1'
-
 
15
 
-
 
16
class BrandAndModelExtracter:
-
 
17
    
-
 
18
    def __init__(self):
-
 
19
        
-
 
20
        try:
-
 
21
            client = CatalogClient().get_client()
-
 
22
            self.brands = client.getAllBrandsByCategory(10001)
-
 
23
        except Exception:
-
 
24
            self.brands = ['Micromax', 'BlackBerry', 'Blackberry', 'Motorola', 'Alcatel', 'Sony Ericsson', 'Apple', \
-
 
25
                      'Spice', 'Nokia', 'HTC', 'Samsung', 'LG', 'Dell', 'Karbonn', 'Lava']
-
 
26
        
-
 
27
        self.brands.append('Blackberry') #To resolve issue of 'BlackBerry' and 'Blackberry'
-
 
28
    
-
 
29
    def extract(self, full_name):
-
 
30
        
-
 
31
        for brand in self.brands:
-
 
32
            if full_name.startswith(brand):  return (brand, full_name.replace(brand, '').strip())
-
 
33
        
-
 
34
        return ("", full_name)
-
 
35
 
14
def isValidRule(rule):
36
def isValidRule(rule):
15
    try:
37
    try:
16
        if rule is None:
38
        if rule is None:
17
            return False
39
            return False
18
        
40
        
Line 25... Line 47...
25
        else:
47
        else:
26
            return True
48
            return True
27
    
49
    
28
    except KeyError:
50
    except KeyError:
29
        return False
51
        return False
30
    
-
 
31
def extractBrandAndName(full_name):
-
 
32
#    brands = ('Micromax', 'BlackBerry', 'Blackberry', 'Motorola', 'Alcatel', 'Sony Ericsson', 'Apple', 'Spice', 'Nokia', 'HTC', 'Samsung', 'LG', 'Dell')
-
 
33
    
-
 
34
    try:
-
 
35
        client = CatalogClient().get_client()
-
 
36
        brands = client.getAllBrandsByCategory(10001)
-
 
37
        brands.append('Blackberry') #To resolve issue of 'BlackBerry' and 'Blackberry'
-
 
38
        
-
 
39
        print brands
-
 
40
        
-
 
41
        for brand in brands:
-
 
42
            if full_name.startswith(brand):  return (brand, full_name.replace(brand, '').strip())
-
 
43
    except Exception as e:
-
 
44
        print e
-
 
45
    
-
 
46
    return ("", full_name)
-
 
47
 
52
 
48
def getItemsWithTopScore(items):
53
def getItemsWithTopScore(items):
49
    filterd_items = []
54
    filterd_items = []
50
    top_score = -1.0
55
    top_score = -1.0
51
    
56
    
Line 97... Line 102...
97
            if isPriceSame(products):
102
            if isPriceSame(products):
98
                display_info[source]['price'] = products[0]['price']
103
                display_info[source]['price'] = products[0]['price']
99
                display_info[source]['data'] = None
104
                display_info[source]['data'] = None
100
                display_info[source]['url'] = products[0]['url']
105
                display_info[source]['url'] = products[0]['url']
101
                display_info[source]['text'] = removePriceFormatting(products[0]['price'])
106
                display_info[source]['text'] = removePriceFormatting(products[0]['price'])
-
 
107
                display_info[source]['title'] = products[0]['name']
102
            else:
108
            else:
103
                display_info[source]['price'] = None
109
                display_info[source]['price'] = None
104
                display_info[source]['data'] = json.dumps(products)
110
                display_info[source]['data'] = json.dumps(products)
105
                display_info[source]['url'] = None
111
                display_info[source]['url'] = None
106
                display_info[source]['text'] = 'Conflict'
112
                display_info[source]['text'] = 'Conflict'
Line 108... Line 114...
108
            display_info[source]['price'] = None
114
            display_info[source]['price'] = None
109
            display_info[source]['data'] = None
115
            display_info[source]['data'] = None
110
            display_info[source]['url'] = None
116
            display_info[source]['url'] = None
111
            display_info[source]['text'] = 'Not Found'
117
            display_info[source]['text'] = 'Not Found'
112
    
118
    
113
    return display_info
-
 
114
119
    return display_info
-
 
120
 
-
 
121
def getSynonyms():
-
 
122
    file_path = '/tmp/synonyms.json'
-
 
123
    file = open(file_path, 'r')
-
 
124
    synonyms_json = file.read()
-
 
125
 
-
 
126
    synonyms = {}
-
 
127
    for key, value in json.loads(synonyms_json).iteritems():
-
 
128
        list_synonyms = []
-
 
129
        
-
 
130
        if 'MODEL_NAME' in value:
-
 
131
            list_synonyms.extend(value['MODEL_NAME'])
-
 
132
            
-
 
133
        if 'MODEL_NUMBER' in value:
-
 
134
            list_synonyms.extend(value['MODEL_NUMBER'])
-
 
135
        
-
 
136
        synonyms[int(key)] = list_synonyms
-
 
137
    
-
 
138
    return synonyms
-
 
139
 
-
 
140
if __name__ == '__main__':
-
 
141
    extracter = BrandAndModelExtracter()
-
 
142
#    print extracter.extract('Nokia X5-01 (Pink)')
-
 
143
    print getSynonyms()
-
 
144
115
145