rabin 7 سال پیش
والد
کامیت
411eacf55d
1فایلهای تغییر یافته به همراه13 افزوده شده و 3 حذف شده
  1. 13 3
      service/ssgdfs.py

+ 13 - 3
service/ssgdfs.py

@@ -38,10 +38,12 @@ class Ssgdfs(object):
 
 	def buy(self, config):
 		product = Demeter.service('product')
+		self.num = 0
 		while 1:
 			state = self.check(config['link'])
 			if state == True:
 				try:
+					self.num = 0
 					print('get' + config['link'])
 					product.status(config['id'], 3)
 					# 下单
@@ -59,7 +61,15 @@ class Ssgdfs(object):
 					product.status(config['id'], 2)
 					continue
 			else:
-				gevent.sleep(30)
+				self.num = self.num + 1
+				self.close()
+				if self.num >= 10:
+					self.quit()
+					product.status(config['id'], 1)
+					print 'kill'
+					break
+				else:
+					gevent.sleep(30)
 
 	def check(self, product):
 		#r = requests.get(product)
@@ -72,7 +82,6 @@ class Ssgdfs(object):
 		if string in data:
 			return True
 		else:
-			self.close()
 			return False
 
 	def open(self):
@@ -100,6 +109,7 @@ class Ssgdfs(object):
 		self.driver.find_element_by_id('login-password').send_keys(self.config['password'])
 		self.driver.find_element_by_xpath('//input[@alt="login"]').click()
 		self.driver.implicitly_wait(5)
+		self.close()
 
 	def order(self, product):
 		#self.get('http://cn.ssgdfm.com/shop/common/cookieEnable?ce=null&returnUrl=%2Fshop%2Fproduct%2FproductDetail%3FprdtCode%3D05710004801')
@@ -180,7 +190,7 @@ class Ssgdfs(object):
 		self.driver.implicitly_wait(10)
 
 	def close(self):
-		self.driver.quit()
+		self.driver.close()
 		#self.driver.close()
 		#self.display.stop()