| 15866 |
kshitij.so |
1 |
import pymongo
|
|
|
2 |
from dtr.utils.utils import to_java_date
|
|
|
3 |
import optparse
|
|
|
4 |
from datetime import datetime
|
|
|
5 |
from dtr.utils import ShopCluesScraper
|
|
|
6 |
import traceback
|
|
|
7 |
|
|
|
8 |
con = None
|
|
|
9 |
parser = optparse.OptionParser()
|
|
|
10 |
parser.add_option("-m", "--m", dest="mongoHost",
|
|
|
11 |
default="localhost",
|
|
|
12 |
type="string", help="The HOST where the mongo server is running",
|
|
|
13 |
metavar="mongo_host")
|
|
|
14 |
|
|
|
15 |
(options, args) = parser.parse_args()
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
exceptionList = []
|
|
|
19 |
now = datetime.now()
|
|
|
20 |
sc = ShopCluesScraper.ShopCluesScraper()
|
|
|
21 |
|
|
|
22 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
|
|
23 |
global con
|
|
|
24 |
if con is None:
|
|
|
25 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
26 |
try:
|
|
|
27 |
con = pymongo.MongoClient(host, port)
|
|
|
28 |
except Exception, e:
|
|
|
29 |
print e
|
|
|
30 |
return None
|
|
|
31 |
return con
|
|
|
32 |
|
|
|
33 |
def getAllProductsToSync():
|
|
|
34 |
global exceptionList
|
|
|
35 |
all_products = get_mongo_connection().Catalog.MasterData.find({'source':"shopclues.com"})
|
|
|
36 |
for product in all_products:
|
|
|
37 |
print product['_id']
|
|
|
38 |
try:
|
|
|
39 |
result = sc.read(product['url'])
|
|
|
40 |
print result
|
|
|
41 |
except:
|
|
|
42 |
traceback.print_exc()
|
|
|
43 |
exceptionList.append(product['_id'])
|
|
|
44 |
continue
|
| 15883 |
kshitij.so |
45 |
get_mongo_connection().Catalog.MasterData.update({'_id':product['_id']},{'$set':{'codAvailable':result['isCod'], 'coupon':result['coupon'], 'in_stock':result['inStock'], 'available_price':result['price'], \
|
| 15866 |
kshitij.so |
46 |
'identifier':result['scin']}}, multi=False, upsert=False)
|
|
|
47 |
|
|
|
48 |
def correctUrls():
|
|
|
49 |
all_products = get_mongo_connection().Catalog.MasterData.find({'source':"shopclues.com"})
|
|
|
50 |
for product in all_products:
|
|
|
51 |
print product['url']
|
|
|
52 |
url = product['url'][0:product['url'].index('?utm_source')]
|
|
|
53 |
print "======================="
|
|
|
54 |
get_mongo_connection().Catalog.MasterData.update({'_id':product['_id']},{'$set':{'marketPlaceUrl':url}})
|
|
|
55 |
|
|
|
56 |
def correctScin():
|
|
|
57 |
all_products = get_mongo_connection().Catalog.MasterData.find({'source':"shopclues.com"})
|
|
|
58 |
for product in all_products:
|
|
|
59 |
if len(product['identifier'])!=0:
|
|
|
60 |
continue
|
|
|
61 |
print product['_id']
|
|
|
62 |
try:
|
|
|
63 |
result = sc.read(product['marketPlaceUrl'])
|
|
|
64 |
except:
|
|
|
65 |
continue
|
|
|
66 |
print result
|
|
|
67 |
get_mongo_connection().Catalog.MasterData.update({'_id':product['_id']},{'$set':{'identifier':result}})
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
def main():
|
| 15887 |
kshitij.so |
72 |
getAllProductsToSync()
|
| 15866 |
kshitij.so |
73 |
#print "Exception list"
|
|
|
74 |
#for e in exceptionList:
|
|
|
75 |
# print e
|
| 16006 |
kshitij.so |
76 |
correctUrls()
|
| 15887 |
kshitij.so |
77 |
#correctScin()
|
| 15866 |
kshitij.so |
78 |
|
|
|
79 |
if __name__=='__main__':
|
|
|
80 |
main()
|