Subversion Repositories SmartDukaan

Rev

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

Rev 16086 Rev 16087
Line 119... Line 119...
119
    stock = 0
119
    stock = 0
120
    try:
120
    try:
121
        req = urllib2.Request(url,headers=headers)
121
        req = urllib2.Request(url,headers=headers)
122
        response = urllib2.urlopen(req)
122
        response = urllib2.urlopen(req)
123
        snapdeal_data = response.read()
123
        snapdeal_data = response.read()
-
 
124
        response.close()
124
    except:
125
    except:
125
        print "Unable to scrape %d"%(data['_id'])
126
        print "Unable to scrape %d"%(data['_id'])
-
 
127
        get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now())}})
-
 
128
        get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0}})
126
        return
129
        return
127
    finally:
-
 
128
        response.close()
-
 
129
    encoding =  chardet.detect(snapdeal_data)
130
    encoding =  chardet.detect(snapdeal_data)
130
    try:
131
    try:
131
        snapdeal_data = snapdeal_data.decode(encoding.get('encoding'))
132
        snapdeal_data = snapdeal_data.decode(encoding.get('encoding'))
132
    except:
133
    except:
133
        snapdeal_data = snapdeal_data.decode(encoding.get('latin-1'))
134
        snapdeal_data = snapdeal_data.decode(encoding.get('latin-1'))