Exemple #1
0
 def run_task(self, task):
     success = False
     fakeloop = True
     state = ""
     while fakeloop:
         try:
             imp = str(task["imp"])
             ua = str(task["ua"])
             headers = task["headers"]
             cookie_file = "%s/runtime/cookies/ati_slave.%d" % (
                 sys.path[0], threading.current_thread().ident)
             options = {}
             options[pycurl.USERAGENT] = ua
             options[pycurl.COOKIEJAR] = cookie_file
             if "referrer" in headers and headers["referrer"]:
                 options[pycurl.REFERER] = str(headers["referrer"])
             code, html = curl_methods.curl_get(imp, options)
             if code != 200 and code != 302:
                 break
             clk = str(task["clk"])
             if clk:
                 delay = 1 + min(3**numpy.random.normal(), 10)
                 time.sleep(delay)
                 options = {}
                 options[pycurl.USERAGENT] = ua
                 options[pycurl.COOKIEFILE] = cookie_file
                 code, html = curl_methods.curl_get(clk, options)
                 if code != 200 and code != 302:
                     break
             success = True
         except Exception, e:
             console.log.warning("%r" % e)
             break
         fakeloop = False
Exemple #2
0
def get_pptp_account(key, uuid):
    account = {}
    api_url = "http://172.16.26.112:37000/api/pptp/account/%s/%s" % (key, uuid)
    code, html = curl_methods.curl_get(api_url)
    if code == 200:
        try:
            account = json.loads(html.strip())
        except Exception, e:
            console.log.warning("%r" % e)
Exemple #3
0
def get_pptp_route_targets():
    targets = None
    api_url = "http://172.16.26.112:37000/api/pptp/route_targets"
    code, html = curl_methods.curl_get(api_url)
    if code == 200:
        try:
            targets = json.loads(html.strip())
        except Exception, e:
            console.log.warning("%r" % e)
Exemple #4
0
def track_task_by_unit_id(unit_id, imp, clk):
    url = 'http://172.16.47.210:80/track/detail'
    post_data = {
        'client_id': 'test',
        'unit_id': unit_id,
        'detail': {
            'imp': imp,
            'clk': clk
        }
    }
    data = json.dumps(post_data)
    options = {}
    options[pycurl.POSTFIELDS] = data
    options[pycurl.HTTPHEADER] = ['Content-Type: application/json']
    code, html = curl_methods.curl_get(url, options)
Exemple #5
0
 def receive_tasks(self):
     while len(self.tasks) < self.capacity:
         # backlog
         message = None
         try:
             message = self.backlog.get(block = False)
         except Exception, e:
             pass
         # fresh message
         if not message:
             #to do@jiangtu api_url
             api_url = "http://172.16.47.210:80/get_task/bidding?client_id=test&task_type=0"
             code, html = curl_methods.curl_get(api_url)
             if code == 200:
                 try:
                     message = json.loads(html.strip())["task"]
                 except Exception, e:
                     console.log.warning("%r %r" % (e, html))
Exemple #6
0
def track_task(taskinfo):
    api_url = "http://172.16.26.112:37000/api/track/slave/%s" % str(taskinfo)
    code, html = curl_methods.curl_get(api_url)
    return (code == 200)
Exemple #7
0
def track_pptp(pptpinfo):
    api_url = "http://172.16.26.112:37000/api/pptp/track/%s" % str(pptpinfo)
    code, html = curl_methods.curl_get(api_url)