def process(self):
     self.truncate_table()
     url = "http://127.0.0.1:8000/?types=0&count=%d&country=国内" % (
         self.proxy_num)
     respond = requests.get(url)
     page = respond.content
     _proxies = json.loads(page)
     proxies = []
     for _proxy in _proxies:
         ip = _proxy[0]
         port = _proxy[1]
         proxy = str(ip) + ":" + str(port)
         proxies.append([proxy])
     db = MysqlHandle()
     sql = "INSERT INTO AI_PROXY_IPS VALUES (%s,NOW(),100)"
     db.insert(sql=sql, value_list=proxies)
     db.close()
示例#2
0
 def main_process(self):
     while not self.queue.empty():
         url = self.queue.get_nowait()
         collect = Collector(url, self.test_url)
         collect.collect_proxy()
         collect.vertify_proxy()
         db = MysqlHandle()
         insert_sql = 'INSERT INTO AI_PROXY_IPS VALUES (%s,NOW(),100)'
         is_success = db.insert(insert_sql, collect.avaliable_ips)
         if is_success:
             print r'oh,successfully collected proxy from ' + url
         else:
             print r'sorry,unsuccessfully collected proxy from ' + url
         db.close()
         time.sleep(3)
示例#3
0
    def GET(self):
        inputs = web.input()
        if inputs.has_key("token"):
            token = inputs["token"]
            if token == "whanys":
                if inputs.has_key("username") and inputs.has_key("password"):
                    username = inputs["username"]
                    password = inputs["password"]
                    sql = "select * from yixin_user where username='******'"
                    db = MysqlHandle()
                    res = db.query(sql)
                    if res:
                        result = {
                            "status": "1",
                            "msg": "failed,the username is already exist!"
                        }
                    else:
                        m = hashlib.md5()
                        m.update(username+"anys"+str(time.time())+password)
                        out_st = m.hexdigest()
                        db = MysqlHandle()
                        sql = "insert into yixin_user (username,password,register_date,status,remain_days,recharge_car) VALUES(%s,%s,now(),1,0,%s)"
                        res = db.insert(sql, [(username, password, out_st)])
                        if res:
                            result = {
                                "status": "0",
                                "msg": "success"
                            }

                else:
                    result = {
                        "status": "1",
                        "msg": "failed,parameters not enough!"
                    }
            else:
                result = {
                    "status": "1",
                    "msg": "failed,your token is not true!"
                }
        else:
            result = {
                "status": "1",
                "msg": "failed,you need a token!"
            }
        return result