Example #1
0
 def testParse(self, url):
     the_data = aituans.httpGetUrlContent(url)
     if the_data == False:
         return False
     self.meta = {"name":"test", "domain":"test.com.cn", "url":"test.com.cn/test", "area":"Beijing", "class":"testclass"}
     self.meta['soup'] = BeautifulSoup.BeautifulSoup(the_data)
     #try:
     self.parse(url)
     #except Exception, e:
     #    print e
      #   return False
     return self.getAttrs()
Example #2
0
 def updateBuys(self, product_data):
     page_data = aituans.httpGetUrlContent(product_data['url'])
     self.meta['soup'] = BeautifulSoup.BeautifulSoup(page_data)
     try:
         self.parse()
         if self.buys == product_data['buys']:
             return True
         # 更新数据库
         db = aituans.mongodbConnection()
         col = db.products
         col.update({"_id":bson.objectid.ObjectId(product_data['_id'])}, {"$set":{"buys": self.buys}})
         file = open("%s/log/updator_count.log" % aituans.ROOT_PATH, "a")
         file.write("%s %s %d %d %s\n" % (time.strftime("%Y-%m-%d- %H:%M:%S", time.localtime(time.time())), product_data["_id"], product_data["buys"], self.buys, product_data['url']))
         file.close()
     except Exception, e:
         file = open("%s/log/updator_count.log" % aituans.ROOT_PATH, "a")
         file.write("%s %s %d %s failed: %s\n" % (time.strftime("%Y-%m-%d- %H:%M:%S", time.localtime(time.time())), product_data["_id"], product_data["buys"], product_data['url'], e))
         file.close()
         return False