def cronOrder(self, merchantid, first=False): mer = Merchant.objects.filter(id = merchantid)[0] try: if not first: nowt = datetime.datetime.now() if isactive(mer.netspider_time.replace(tzinfo=None), det=19): return True mer.netspider_time = datetime.datetime.now() meires = None print('%s is online' % mer.name) CatcheData.objects.get_or_create(merchant=mer) if mer.ele_account != '' and mer.ele_status is True: elecat = Ele(merchantid, self.__use_proxy) eleres = elecat.catcheorder(mer) if mer.mei_account != '' and mer.mei_status is True: print 'mei excet' meicat = Mei(merchantid, self.__use_proxy) meires = meicat.getOrder(mer) if mer.tao_account != '' and mer.tao_status is True: tddcat = Tao() tddres = tddcat.getpaddingorder(mer) mer.save() return meires except Exception, e: mer.save() print 'ALO ERROR' except_handle(e)
def getproxy(args = None): a = NetProcess() a.Host = 'www.hao123.com' errmsg = '' myproxy = SProxy() ip_list = myproxy.renew_proxy() newitems = 0 for item in ip_list: try: ishave = Proxy.objects.filter(ip = str(item)) if ishave.count() > 0: continue a.Proxy = item res = a.GetResFromRequest('GET', "http://www.hao123.com/", 'utf-8', use_proxy=True) if isinstance(res, str): newitems += 1 newproxy = Proxy() newproxy.ip = item newproxy.is_online = True newproxy.is_used = False newproxy.req_times = 0 newproxy.get_time = datetime.datetime.now() newproxy.save() except Exception, e: except_handle(e) errmsg = str(e) continue
def isactive(lastactivetime, det=600): try: print lastactivetime nowt = datetime.datetime.utcnow() print nowt detla = nowt - lastactivetime if detla > datetime.timedelta(seconds=det): return False else: return True except Exception, e: except_handle(e)