# Path: app/NetProcess.py
# class NetProcess(object):
#     def __init__(self):
#         self.__proxy = ''
#         self.__cookies = {}
#         self.__usecookies = False
#         self.__headers = {}
#         self.__useheaders = False
#         self.__grequests = []
# 
#     def getCookies(self): return self.__cookies
#     def setCookies(self, value):self.__cookies = value
#     Cookies = property(getCookies, setCookies, "Property CookieList")
# 
#     def getProxy(self): return self.__proxy
#     def setProxy(self, value):self.__proxy = value
#     Proxy = property(getProxy, setProxy, "Property Proxy")
# 
#     def getHeaders(self): return self.__headers
#     def setHeaders(self, value):self.__headers = value
#     Headers = property(getHeaders, setHeaders, "Property Headers")
# 
# 
# 
#     def GetResFromRequest(self, method, requrl, encodemethod='utf-8', postDic={}, reqdata='', use_proxy=False, timeout=5):
#         res = None
#         requests.adapters.DEFAULT_RETRIES = 5
#         try:
#             if str(method).upper() == 'POST':
#                 if use_proxy:
#                     scp = 'http://' + self.__proxy
#                     proxy = {"http": scp, }
#                     res = requests.post(requrl, data=postDic, proxies=proxy, cookies=self.__cookies,  headers=self.__headers, timeout=timeout)
#                 else:
#                     res = requests.post(requrl, data=postDic, cookies=self.__cookies, headers=self.__headers, timeout=timeout)
#             elif str(method).upper() == 'GET':
#                 if use_proxy:
#                     scp = 'http://' + self.__proxy
#                     proxy = {"http": scp, }
#                     res = requests.get(requrl, proxies=proxy, cookies=self.__cookies, headers=self.__headers, timeout=timeout)
#                 else:
#                     res = requests.get(requrl, cookies=self.__cookies, headers=self.__headers, timeout=timeout)
#             self.__cookies = res.cookies
#             res.encoding = encodemethod
#             # print res.content
#             return res.content
#         except Exception, e:
#             #print e.message
#             # print e
#             return 'error: %s' % str(e)
#         finally:
#             pass
# 
# 
#     def coroutine_request(self, method, requrl, encodemethod='utf-8', postDic={}, reqdata='', use_proxy=False, timeout=5):
#         if use_proxy:
#             scp = 'http://' + self.__proxy
#             proxy = {"http": scp, }
#             g_req = AsyncRequest(str(method).upper(), requrl, data=postDic, timeout=timeout, proxies=proxy)
#         else:
#             g_req = AsyncRequest(str(method).upper(), requrl, data=postDic, timeout=timeout)
#         self.__grequests.append(g_req)
#         return g_req
# 
# 
#     def coroutine_response(self, size=None, stream=False, exception_handler=None, status_only=False):
#         g_requests = list(self.__grequests)
# 
#         pool = Pool(size) if size else None
#         jobs = [send(r, pool, stream=stream) for r in g_requests]
#         gevent.joinall(jobs)
# 
#         ret = []
#         if status_only:
#             for request in g_requests:
#                 if request.response:
#                     ret.append(copy.copy(True))
#                 else:
#                     ret.append(copy.copy(False))
#             return ret
# 
#         for request in g_requests:
#             if request.response:
#                 ret.append(request.response)
#             elif exception_handler:
#                 exception_handler(request, request.exception)
# 
# 
# 
#         return ret
# 
#     def OutPutCookie(self):
#         res = {}
#         for (itm, key) in self.__cookies.items():
#             res[itm] = key
#         return res
# 
#     def SetCookie(self, cookiestr):
#         cookielist = eval(cookiestr)
#         self.__cookies = cookielist
#         self.__usecookies = True
#         return True
# 
#     def SetHeaders(self, headerdic):
#         self.__headers = headerdic
#         self.__useheaders = True
#         return True


from app.NetProcess import NetProcess
import simplejson
import time


def doit():
    token = 'vf3kDL6bIx1lYjPeT+HuXorgtRZSdNBU'
    ip_list = []
    net = NetProcess()
    data = {'private_token': token}
    res = net.GetResFromRequest('POST', 'http://www.rapospectre.com/lab/get_proxy/', postDic=data)
    json_data = simplejson.loads(res)
    ip_body = json_data['body']['proxy_list']
    for ip in ip_body:
        new_ip = ip['ip']
        ip_list.append(new_ip)
    net.Headers = {'User-Agent': 'Dalvik/1.6.0 (Linux; U; Android 4.1.1; MI 2S MIUI/4.11.7)',
                                'Content-Type': 'application/x-www-form-urlencoded',
                                'Host': '68.64.164.93'}
    for i in ip_list:
        net.Proxy = i
        res = net.GetResFromRequest('GET', 'http://68.64.164.93/u/?id=zjqqq', use_proxy=True, encodemethod='gb2312')
        # print res
        res = net.GetResFromRequest('GET', 'http://68.64.164.93/index.asp?id=zjqqq', use_proxy=True, encodemethod='gb2312')
        # print res



for j in range(1, 100):
    doit()

# Path: app/NetProcess.py
# class NetProcess(object):
#     def __init__(self):
#         self.__proxy = ''
#         self.__cookies = {}
#         self.__usecookies = False
#         self.__headers = {}
#         self.__useheaders = False
#         self.__grequests = []
# 
#     def getCookies(self): return self.__cookies
#     def setCookies(self, value):self.__cookies = value
#     Cookies = property(getCookies, setCookies, "Property CookieList")
# 
#     def getProxy(self): return self.__proxy
#     def setProxy(self, value):self.__proxy = value
#     Proxy = property(getProxy, setProxy, "Property Proxy")
# 
#     def getHeaders(self): return self.__headers
#     def setHeaders(self, value):self.__headers = value
#     Headers = property(getHeaders, setHeaders, "Property Headers")
# 
# 
# 
#     def GetResFromRequest(self, method, requrl, encodemethod='utf-8', postDic={}, reqdata='', use_proxy=False, timeout=5):
#         res = None
#         requests.adapters.DEFAULT_RETRIES = 5
#         try:
#             if str(method).upper() == 'POST':
#                 if use_proxy:
#                     scp = 'http://' + self.__proxy
#                     proxy = {"http": scp, }
#                     res = requests.post(requrl, data=postDic, proxies=proxy, cookies=self.__cookies,  headers=self.__headers, timeout=timeout)
#                 else:
#                     res = requests.post(requrl, data=postDic, cookies=self.__cookies, headers=self.__headers, timeout=timeout)
#             elif str(method).upper() == 'GET':
#                 if use_proxy:
#                     scp = 'http://' + self.__proxy
#                     proxy = {"http": scp, }
#                     res = requests.get(requrl, proxies=proxy, cookies=self.__cookies, headers=self.__headers, timeout=timeout)
#                 else:
#                     res = requests.get(requrl, cookies=self.__cookies, headers=self.__headers, timeout=timeout)
#             self.__cookies = res.cookies
#             res.encoding = encodemethod
#             # print res.content
#             return res.content
#         except Exception, e:
#             #print e.message
#             # print e
#             return 'error: %s' % str(e)
#         finally:
#             pass
# 
# 
#     def coroutine_request(self, method, requrl, encodemethod='utf-8', postDic={}, reqdata='', use_proxy=False, timeout=5):
#         if use_proxy:
#             scp = 'http://' + self.__proxy
#             proxy = {"http": scp, }
#             g_req = AsyncRequest(str(method).upper(), requrl, data=postDic, timeout=timeout, proxies=proxy)
#         else:
#             g_req = AsyncRequest(str(method).upper(), requrl, data=postDic, timeout=timeout)
#         self.__grequests.append(g_req)
#         return g_req
# 
# 
#     def coroutine_response(self, size=None, stream=False, exception_handler=None, status_only=False):
#         g_requests = list(self.__grequests)
# 
#         pool = Pool(size) if size else None
#         jobs = [send(r, pool, stream=stream) for r in g_requests]
#         gevent.joinall(jobs)
# 
#         ret = []
#         if status_only:
#             for request in g_requests:
#                 if request.response:
#                     ret.append(copy.copy(True))
#                 else:
#                     ret.append(copy.copy(False))
#             return ret
# 
#         for request in g_requests:
#             if request.response:
#                 ret.append(request.response)
#             elif exception_handler:
#                 exception_handler(request, request.exception)
# 
# 
# 
#         return ret
# 
#     def OutPutCookie(self):
#         res = {}
#         for (itm, key) in self.__cookies.items():
#             res[itm] = key
#         return res
# 
#     def SetCookie(self, cookiestr):
#         cookielist = eval(cookiestr)
#         self.__cookies = cookielist
#         self.__usecookies = True
#         return True
# 
#     def SetHeaders(self, headerdic):
#         self.__headers = headerdic
#         self.__useheaders = True
#         return True


# Path: app/blog_lab/proxy/cl.py
from app.NetProcess import NetProcess
import simplejson
import time



def doit():
    token = 'vf3kDL6bIx1lYjPeT+HuXorgtRZSdNBU'
    ip_list = []
    net = NetProcess()
    data = {'private_token': token}
    res = net.GetResFromRequest('POST', 'http://www.rapospectre.com/lab/get_proxy/', postDic=data)
    json_data = simplejson.loads(res)
    ip_body = json_data['body']['proxy_list']
    for ip in ip_body:
        new_ip = ip['ip']
        ip_list.append(new_ip)
    net.Headers = {'User-Agent': 'Dalvik/1.6.0 (Linux; U; Android 4.1.1; MI 2S MIUI/4.11.7)',
                                'Content-Type': 'application/x-www-form-urlencoded',
                                'Host': '68.64.164.93'}
    for i in ip_list:
        net.Proxy = i
        res = net.GetResFromRequest('GET', 'http://68.64.164.93/u/?id=zjqqq', use_proxy=True, encodemethod='gb2312')
        # print res
        res = net.GetResFromRequest('GET', 'http://68.64.164.93/index.asp?id=zjqqq', use_proxy=True, encodemethod='gb2312')
        # print res



for j in range(1, 100):
    doit()

    print 'num %i' % j