123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- """
- demeter service
- name:ssgdfs.py ssgdfs网站抢单业务
- author:rabin
- """
- from .__load__ import *
- class Ssgdfs(object):
- def init(self, config):
- self.config = config
- def start(self):
- if 'product' in self.config and self.config['product']:
- try:
-
- self.open()
-
- self.login()
-
- self.core()
-
- self.close()
- except BaseException, e:
- print e
- self.start()
- def core(self):
-
- '''
- task = []
- for v in self.config['product']:
- task.append(gevent.spawn(self.buy, v))
- gevent.joinall(task)
- '''
- for v in self.config['product']:
- self.buy(v)
- def buy(self, config):
- product = Demeter.service('product')
- while 1:
- state = self.check(config['link'])
- if state == True:
- try:
- product.status(config['id'], 3)
-
- self.order(config['link'])
-
- order = product.createOrderId(self.pay(), config['site_id'], config['id'])
-
- pic = self.crop(order, config['id'])
-
- product.order(order, pic, config['site_id'], config['id'])
- product.status(config['id'], 4)
- break
- except BaseException, e:
- print e
- product.status(config['id'], 2)
- continue
- else:
- gevent.sleep(30)
- def check(self, product):
- r = requests.get(product)
-
- string = 'btn_soldout.gif'
- data = r.text
- if string in data:
- return False
- else:
- return True
- def open(self):
-
-
- self.driver = webdriver.Remote(command_executor=Demeter.config['setting']['phantomjs'], desired_capabilities=DesiredCapabilities.PHANTOMJS)
-
-
-
- def login(self):
- self.get(self.config['login_link'])
-
- self.driver.find_element_by_id('login-id').send_keys(self.config['username'])
- 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)
- def order(self, product):
-
- self.get(product)
-
- self.driver.execute_script('directOrderProduct()')
-
- self.wait('long-sub')
-
- self.waitNot('pay_popup')
-
- self.order_content()
-
- self.driver.execute_script('goPaymentCheck()')
-
- self.wait('order-agree2')
- def order_content(self):
-
-
-
- self.driver.find_element_by_class_name('btn-popup-exitInfo').click()
- exit = self.driver.find_elements_by_class_name('btn-red')
- exitLength = len(exit)-1
- rand = random.randint(0, exitLength)
- exit[rand].click()
-
-
- self.driver.find_element_by_xpath('//input[@name="nowUse" and @value="0"]').click()
- def pay(self):
-
- self.waitNot('loding_popup')
-
- self.pay_content()
-
- self.driver.execute_script('window.confirm = function(msg) { return true; }');
-
- self.driver.execute_script('$("a.goPayment").click()')
-
-
- self.wait('qrcode')
- sleep(2)
-
-
-
- order = False
- return order
- def pay_content(self):
-
- self.driver.find_element_by_id('exitDestInfo').click()
-
- self.driver.find_element_by_id('agree').click()
-
- self.driver.find_element_by_id('agree01').click()
-
- self.driver.find_element_by_xpath('//input[@id="pymntMeansCode" and @value="16"]').click()
- def crop(self, order, id):
- path = Demeter.path + 'runtime/upload/'
- if not File.exists(path):
- File.mkdir(path)
- pic = path + str(id) + '_' + str(order) + '.png'
- self.driver.save_screenshot(pic)
- return pic
- def waitNot(self, name):
- WebDriverWait(self.driver, 100).until_not(lambda x: x.find_element_by_class_name(name).is_displayed())
- def wait(self, name):
- WebDriverWait(self.driver, 100).until(lambda x: x.find_element_by_class_name(name).is_displayed())
- def get(self, link):
- self.driver.get(link)
- self.driver.implicitly_wait(10)
- def close(self):
- self.driver.quit()
-
-
|