示例#1
0
 def set_primary_key(self, fields):
     primary_str = ""
     for field in fields:
         primary_str += field + ","
     primary_str = primary_str.strip(",")
     sql = "alter table " + self.table + " add primary key (" + primary_str + ")"
     db = MysqlHandle()
     db.excute(sql=sql)
示例#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") and inputs.has_key("key"):
                    username = inputs["username"]
                    password = inputs["password"]
                    key = inputs["key"]
                    sql = "select recharge_car from yixin_user where username='******' and password='******'"
                    db = MysqlHandle()
                    user_res = db.query(sql)
                    db.close()
                    if user_res:
                        if user_res[0][0] == key:
                            m = hashlib.md5()
                            m.update(username + "anys" + str(time.time()) + password)
                            out_st = m.hexdigest()
                            sql = "update yixin_user set status=0 ,remain_days = remain_days+30 ,recharge_car='"+out_st+"'"+" where username='******' and password='******'"
                            db = MysqlHandle()
                            res = db.update(sql)
                            if res:
                                result = {
                                    "status": "0",
                                    "msg": "success"
                                }
                            else:
                                result = {
                                    "status": "1",
                                    "msg": "failed!unknown error!"
                                }
                        else:
                            result = {
                                "status": "1",
                                "msg": "failed!key error!"
                            }

                    else:
                        result = {
                            "status": "1",
                            "msg": "failed!information error!"
                        }
                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
示例#4
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='******' and password='******' and status=0"
                 db = MysqlHandle()
                 res = db.query(sql)
                 if res:
                     result = {
                         "status": "0",
                         "msg": "success"
                     }
                 else:
                     result = {
                         "status": "1",
                         "msg": "failed!"
                     }
             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
示例#5
0
 def add_number_field(self, field_name, field_length=4, field_precision=0):
     if field_precision == 0:
         sql = "alter table " + self.table + " add " + field_name + " int(" + str(
             field_length) + ")"
     else:
         sql = "alter table " + self.table + " add " + field_name + " double("+str(field_length)+", "\
               + str(field_precision)+")"
     db = MysqlHandle()
     db.excute(sql=sql)
     db.close()
 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()
示例#7
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 not  res:
                        result = {
                            "status": "1",
                            "msg": "failed,the username is not exist!"
                        }
                    else:
                        m = hashlib.md5()
                        m.update(username + "anys" + str(time.time()) + password)
                        out_st = m.hexdigest()
                        db = MysqlHandle()
                        sql = "update yixin_user set recharge_car='"+out_st+"'"+" ,status=0 ,remain_days=30 where username='******'"
                        res = db.update(sql)
                        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
示例#8
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
 def truncate_table(self):
     db = MysqlHandle()
     sql = "truncate table AI_PROXY_IPS"
     db.excute(sql=sql)
     db.close()
示例#10
0
 def drop_field(self, field_name):
     sql_de = "alter table " + self.table + " drop column " + field_name
     db = MysqlHandle()
     db.excute(sql=sql_de)
     db.close()
示例#11
0
 def add_blob_field(self, field_name):
     sql = "alter table " + self.table + " add " + field_name + " blob"
     db = MysqlHandle()
     db.excute(sql=sql)
     db.close()
示例#12
0
 def add_datetime_field(self, field_name):
     sql = "alter table " + self.table + " add " + field_name + " datetime"
     db = MysqlHandle()
     db.excute(sql=sql)
     db.close()
示例#13
0
 def add_char_field(self, field_name, field_length):
     sql = "alter table " + self.table + " add " + field_name + " varchar(" + str(
         field_length) + ")"
     db = MysqlHandle()
     db.excute(sql=sql)
     db.close()
示例#14
0
 def add_medium_blob_field(self, field_name):
     sql = "alter table " + self.table + " add " + field_name + " MEDIUMBLOB"
     db = MysqlHandle()
     db.excute(sql=sql)
     db.close()
示例#15
0
 def create_table(self):
     sql = "create table " + self.table + " (_id_temp_ int)"
     db = MysqlHandle()
     db.excute(sql=sql)
     db.close()