Rev 13846 | Rev 13914 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
import pymongofrom dtr.utils.utils import to_java_datefrom datetime import datetimefrom operator import itemgetterfrom shop2020.model.v1.catalog.script import FlipkartScraperfrom dtr.utils import AmazonPriceOnlyScrapercon = Nonenow = datetime.now()scraperAmazon = AmazonPriceOnlyScraper.AmazonScraper()print to_java_date(now)def get_mongo_connection(host='localhost', port=27017):global conif con is None:print "Establishing connection %s host and port %d" %(host,port)try:con = pymongo.MongoClient(host, port)except Exception, e:print ereturn Nonereturn condef scrapeAmazon():amazonBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0},'source_id':1}))for data in amazonBestSellers:inStock = 0print str(data['identifier'])if data['identifier'] is None or len(data['identifier'].strip())==0:print "continue"continueurl = "http://www.amazon.in/gp/offer-listing/%s/ref=olp_sort_ps"%(data['identifier'].strip())print urllowestPrice = 0.0lowestPrice = scraperAmazon.read(url)print lowestPriceif lowestPrice > 0:inStock = 1print lowestPriceprint inStockif lowestPrice > 0:get_mongo_connection().Catalog.MasterData.update({'identifier':data['identifier'].strip(),'source_id':1}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(now),'in_stock':inStock}}, multi=True)else:get_mongo_connection().Catalog.MasterData.update({'identifier':data['identifier'].strip(),'source_id':1}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':inStock}}, multi=True)print "+++++++++++++++++++++++++++"def main():scrapeAmazon()if __name__=='__main__':main()