def add_tai_yang(redis_host="127.0.0.1", db=11): r = redis.Redis(redis_host, db=db) url = "http://http-api.taiyangruanjian.com/getip?num=1&type" \ "=2&pro=&city=0&yys=0&port=11&pack=13604&ts=1&ys=0&cs=0&lb=1&sb=0&pb=4&mr=0®ions=" while True: time.sleep(1) if r.dbsize() < 3: resp = Rh.RequestHelper.send_cache_request(url) if resp.status == 200: try: json_data = json.loads(resp.text) if json_data["code"] == 0: ip = str(json_data["data"][0]["ip"]) + ":" + str( json_data["data"][0]["port"]) ets = int( Dt.str_to_ts(json_data["data"][0]["expire_time"]) - time.time() + 1) d("OK " + json_data["data"][0]["expire_time"] + " ====== now + " + str(ets // 60), line1="===") r.set(ip, 0, ex=ets) time.sleep(1) except: print("not json data" + resp.text) traceback.print_exc() else: print("proxy return error" + str(resp.text)) else: break return 1
def add_zhima(r): url = "http://webapi.http.zhimacangku.com/getip?num=1&type=2&pro=&city=0&yys=0&port=1&pack=15624&ts=1&ys=0&cs=0&lb=1&sb=0&pb=4&mr=1®ions=" while True: time.sleep(1) if r.dbsize() < 2: resp = Rh.RequestHelper.send_cache_request(url) if resp.status == 200: try: json_data = json.loads(resp.text) if json_data["code"] == 0: ip = str(json_data["data"][0]["ip"]) + ":" + str( json_data["data"][0]["port"]) ets = int( Dt.str_to_ts(json_data["data"][0]["expire_time"]) - time.time() + 1) d("OK " + json_data["data"][0]["expire_time"] + " ====== now + " + str(ets // 60), line1="===") r.set(ip, 0, ex=ets) time.sleep(1) else: print(json_data) except: print("not json data" + resp.text) traceback.print_exc() else: print("proxy return error" + str(resp.text)) else: print("Enough") time.sleep(10)