Пример #1
0
 def select_role(self, imei):
     sql = 'select * from user where imei = %s;' % imei
     self.cursor.execute(sql)
     user = self.cursor.fetchone()
     if user:
         return server_return.server_success({'role': user[INDEX_ROLE]})
     else:
         insert_result = self._save_new_user(imei, None, None, None)
         if insert_result['code'] == 200:
             return server_return.server_success('normal')
         else:
             return insert_result
Пример #2
0
 def select_role(self, imei):
     sql = 'select * from user where imei = %s;' % imei
     self.cursor.execute(sql)
     user = self.cursor.fetchone()
     if user:
         return server_return.server_success({'role': user[INDEX_ROLE]})
     else:
         insert_result = self._save_new_user(imei, None, None, None)
         if insert_result['code'] == 200:
             return server_return.server_success('normal')
         else:
             return insert_result
Пример #3
0
def upload_apk():
    if 'version_code' in request.form and 'version_name' in request.form and 'file' in request.files and _check_sign(
            request.form):
        form = request.form
        is_current = form.get('is_current', 0)
        is_force = form.get('is_force', 0)
        message = form.get('message', None)
        directory = _get_directory()
        file = request.files['file']
        if 'apk' in file.filename:
            print(file, type(file))
            fn = _get_filename(file.filename, directory)
            file.save(directory + '/' + fn)

            client().save_version(file_name=fn,
                                  version_code=int(form.get('version_code')),
                                  version_name=form.get('version_name'),
                                  is_current=int(is_current),
                                  message=message,
                                  is_force=is_force)
            return server_return.server_success({'m': '上传成功'})
        else:
            return server_return.server_error(server_return.ERROR_SIGN,
                                              '文件格式有误')
    else:
        return server_return.server_error(server_return.ERROR_SIGN)
Пример #4
0
 def mark_out(self, id, logout_time):
     update_sql = 'update {table} set logout_time = \"{logout_time}\" where id=\"{id}\";' \
         .format(table=TABLE_USER_LOG, logout_time=logout_time, id=id)
     try:
         print('mark_out:', update_sql)
         self.cursor.execute(update_sql)
         self.db.commit()
         return server_return.server_success('更新成功')
     except:
         return server_return.server_error(server_return.ERROR_DB)
Пример #5
0
 def mark_out(self, id, logout_time):
     update_sql = 'update {table} set logout_time = \"{logout_time}\" where id=\"{id}\";' \
         .format(table=TABLE_USER_LOG, logout_time=logout_time, id=id)
     try:
         print('mark_out:', update_sql)
         self.cursor.execute(update_sql)
         self.db.commit()
         return server_return.server_success('更新成功')
     except:
         return server_return.server_error(server_return.ERROR_DB)
Пример #6
0
def show_pic(filename):
    directory = _get_directory()
    f = directory + '/' + filename
    b = os.path.isfile(f)
    if b:
        image_f = open(f, 'rb')
        image_data = image_f.read()
        image_f.close()
        response = make_response(image_data)
        response.headers['Content-Type'] = 'image/png'
        return response
    return server_return.server_success({'b': b})
Пример #7
0
def show_pic(filename):
    directory = _get_directory()
    f = directory + '/' + filename
    b = os.path.isfile(f)
    if b:
        image_f = open(f, 'rb')
        image_data = image_f.read()
        image_f.close()
        response = make_response(image_data)
        response.headers['Content-Type'] = 'image/png'
        return response
    return server_return.server_success({'b': b})
Пример #8
0
def upload_file():
    if 'file' in request.files and 'sign' in request.form and 'time_stamp' in request.form:
        if request.form.get('sign', None) == _get_sign(request.form.get('time_stamp', None)):
            directory = _get_directory()
            file = request.files['file']
            print(file, type(file))
            file.save(directory + '/' + _get_filename(file.filename, directory))

            return server_return.server_success({'m': '上传成功'})
        else:
            return server_return.server_error(server_return.ERROR_SIGN)
    else:
        return server_return.server_error(server_return.ERROR_PARAMS)
Пример #9
0
def upload_file():
    if 'file' in request.files and 'sign' in request.form and 'time_stamp' in request.form:
        if request.form.get('sign', None) == _get_sign(
                request.form.get('time_stamp', None)):
            directory = _get_directory()
            file = request.files['file']
            print(file, type(file))
            file.save(directory + '/' +
                      _get_filename(file.filename, directory))

            return server_return.server_success({'m': '上传成功'})
        else:
            return server_return.server_error(server_return.ERROR_SIGN)
    else:
        return server_return.server_error(server_return.ERROR_PARAMS)
Пример #10
0
 def create_user(self, root_imei, imei, role, usable, name):
     """
     创建/更新用户(更新时,只改变role,name和usable字段)
     :param root_imei:
     :param imei:
     :param role:
     :param usable:
     :param name:
     :return:
     """
     self.cursor.execute(
         'select role from {table} where imei = {imei};'.format(
             table=TABLE_USER, imei=root_imei))
     # root_role = self.cursor.fetchone()
     # print(type(root_role), root_role)
     if self.cursor.fetchone()[0] == 'root':
         count_sql = 'select count(*) from user where imei = "{imei}";'.format(
             imei=imei)
         self.cursor.execute(count_sql)
         if self.cursor.fetchone()[0] == 0:
             # 插入新用户
             return self._save_new_normal_user(imei, root_imei, usable,
                                               name)
         else:
             # 更新 只改变role,name和usable字段
             self.cursor.execute(
                 'select * from user where imei = "{imei}";'.format(
                     imei=imei))
             user = self.cursor.fetchone()
             print('更新 select')
             print(user)
             _role = user[3] if role is None else role
             _usable = user[5] if usable is None else usable
             # _name = '' if name is None else name
             update_sql = 'update {table} set role=\"{role}\",usable={usable},name=\"{name}\" where imei ={imei};' \
                 .format(table=TABLE_USER, role=_role, imei=imei, usable=_usable, name=name)
             try:
                 print('更新', update_sql)
                 self.cursor.execute(update_sql)
                 self.db.commit()
                 return server_return.server_success('更新成功')
             except:
                 return server_return.server_error(server_return.ERROR_DB)
     else:
         return server_return.server_error(ERROR_PERMISSION_DE)
Пример #11
0
    def check_version(self):
        select_sql = 'select * from versions where is_current = 1;'
        self.cursor.execute(select_sql)
        version = self.cursor.fetchone()
        print(version)
        # if current_version:
        #     # print('===', current_version)
        #     db_version_code = int(current_version[1])
        #     if db_version_code < version_code:
        #         insert_sql = 'insert into versions(version_code,version_name,is_current,create_time) values({version_code},\"{version_name}\",1,curdate())'.format(
        #             version_code=version_code, version_name=version_name)
        #         update_sql = 'update versions set is_current = 0 where id = {id}'.format(id=current_version[0])
        #         self.cursor.execute(insert_sql)
        #         self.cursor.execute(update_sql)
        #         self.db.commit()
        #         return server_return.server_success(
        #             {'version_code': version_code, 'version_name': version_name, 'is_current': 1})
        #     else:
        #         return server_return.server_success(
        #             {'version_code': current_version[1], 'version_name': current_version[2],
        #              'is_current': current_version[3]})
        #
        # else:
        #     insert_sql = 'insert into versions(version_code,version_name,is_current,create_time) values({version_code},\"{version_name}\",1,curdate())'.format(
        #         version_code=version_code, version_name=version_name)
        #     self.cursor.execute(insert_sql)
        #     self.db.commit()

        t=version[4]
        t2=t.strftime('%Y-%m-%d %H:%M:%S')
        print(type(t),t)
        print("t2",t2)
        r = {
            'version_code': version[1],
            'version_name': version[2],
            'is_current': version[3],
            'create_time': version[4].strftime('%Y-%m-%d %H:%M:%S'),
            'message': version[5],
            'url': version[6],
            'is_force': version[7],
        }
        return server_return.server_success(r)
Пример #12
0
    def mark_in(self, imei, login_time, local, ip, version_code, version_name):
        select_sql = 'select * from {table} where imei = {imei}' \
            .format(table=TABLE_USER, imei=imei)
        self.cursor.execute(select_sql)
        user = self.cursor.fetchone()
        if user:
            user_id = user[INDEX_ID]
            username = user[INDEX_NAME]
            values_str = ' values({user_id},\"{imei}\",\"{login_time}\"' \
                .format(user_id=user_id, imei=imei, login_time=login_time)
            insert_sql = 'insert into {table}(user_id,imei,login_time'.format(
                table=TABLE_USER_LOG)
            if username:
                insert_sql += ',username'
                values_str += ',\"{username}\"'.format(username=username)
            if local:
                insert_sql += ',local'
                values_str += ',\"{local}\"'.format(local=local)
            if ip:
                insert_sql += ',ip'
                values_str += ',\"{ip}\"'.format(ip=ip)
            if version_code:
                insert_sql += ',version_code'
                values_str += ',{version_code}'.format(
                    version_code=version_code)
            if version_name:
                insert_sql += ',version_name'
                values_str += ',\"{version_name}\"'.format(
                    version_name=version_name)
            f_insert_sql = insert_sql + ')' + values_str + ');'

            print('mark_in', f_insert_sql)

            try:
                self.cursor.execute(f_insert_sql)
                lastrowid = self.cursor.lastrowid
                self.db.commit()
                return server_return.server_success({'mark_id': lastrowid})
            except:
                return server_return.server_error(server_return.ERROR_DB)
        else:
            return server_return.server_error(server_return.ERROR_DB, '用户不存在')
Пример #13
0
    def check_version(self):
        select_sql = 'select * from versions where is_current = 1;'
        self.cursor.execute(select_sql)
        version = self.cursor.fetchone()
        print(version)
        # if current_version:
        #     # print('===', current_version)
        #     db_version_code = int(current_version[1])
        #     if db_version_code < version_code:
        #         insert_sql = 'insert into versions(version_code,version_name,is_current,create_time) values({version_code},\"{version_name}\",1,curdate())'.format(
        #             version_code=version_code, version_name=version_name)
        #         update_sql = 'update versions set is_current = 0 where id = {id}'.format(id=current_version[0])
        #         self.cursor.execute(insert_sql)
        #         self.cursor.execute(update_sql)
        #         self.db.commit()
        #         return server_return.server_success(
        #             {'version_code': version_code, 'version_name': version_name, 'is_current': 1})
        #     else:
        #         return server_return.server_success(
        #             {'version_code': current_version[1], 'version_name': current_version[2],
        #              'is_current': current_version[3]})
        #
        # else:
        #     insert_sql = 'insert into versions(version_code,version_name,is_current,create_time) values({version_code},\"{version_name}\",1,curdate())'.format(
        #         version_code=version_code, version_name=version_name)
        #     self.cursor.execute(insert_sql)
        #     self.db.commit()

        t = version[4]
        t2 = t.strftime('%Y-%m-%d %H:%M:%S')
        print(type(t), t)
        print("t2", t2)
        r = {
            'version_code': version[1],
            'version_name': version[2],
            'is_current': version[3],
            'create_time': version[4].strftime('%Y-%m-%d %H:%M:%S'),
            'message': version[5],
            'url': version[6],
            'is_force': version[7],
        }
        return server_return.server_success(r)
Пример #14
0
def maoyan_board():
    sign = request.args.get('sign', None)
    tag = request.args.get('tag', 0)
    page_num = request.args.get('page_num', 1)
    page_size = request.args.get('page_size', 10)
    time_stamp = request.args.get('time_stamp', 0)

    print(time_stamp, int(time.time()))
    if sign and time_stamp:
        hl = md5()
        hl.update(('我是大帅哥' + time_stamp).encode(encoding='utf-8'))
        mm = hl.hexdigest()
        print('sign:{sign},mm:{mm}'.format(sign=sign, mm=mm))
        if sign == mm:
            j = get_maoyan_control().get_data(tag=tag, page_num=page_num, page_size=page_size)
            return server_return.server_success(j)
        else:
            return server_return.server_error(server_return.ERROR_PARAMS)
    else:
        return server_return.server_error(server_return.ERROR_PARAMS)
Пример #15
0
 def mark_in_ip(self, ip, mark_id):
     local = None
     try:
         res = requests.get('http://ip.zxinc.org/ipquery/?ip={ip}'.format(ip=ip))
         selector = Selector(text=res.text)
         local = selector.xpath('//form[@method="get"]//tr[4]/td[2]/text()').extract_first()
     except:
         pass
     sets = 'ip=\"{ip}\"'.format(ip=ip)
     if local:
         sets += ',local=\"{local}\"'.format(local=local)
     update_sql = 'update {table} set {sets} where id = {mark_id}'.format(table=TABLE_USER_LOG, sets=sets,
                                                                          mark_id=mark_id)
     print('update_sql', update_sql)
     try:
         self.cursor.execute(update_sql)
         self.db.commit()
         return server_return.server_success('更新成功')
     except:
         return server_return.server_error(server_return.ERROR_DB, update_sql)
Пример #16
0
 def mark_movie(self, imei, movie_id, movie_name, downloaded_time, downloaded_timestamp):
     select_url = "select * from {table} where imei = \"{imei}\";".format(table=TABLE_USER, imei=imei)
     self.cursor.execute(select_url)
     user = self.cursor.fetchone()
     if user:
         user_id = user[INDEX_ID]
         user_name = user[INDEX_NAME]
         sql = 'insert into {table}(userId,userName,movieId,movieName,downloaded_time,' \
               'downloaded_timestamp) values({userId},\"{userName}\",{movieId},\"{movieName}\",\"{downloaded_time}\",' \
               '{downloaded_timestamp});'.format(table=TABLE_USER_MOVIE, userId=user_id, userName=user_name,
                                                 movieId=movie_id, movieName=movie_name,
                                                 downloaded_time=downloaded_time,
                                                 downloaded_timestamp=downloaded_timestamp)
         try:
             print('记录数据', sql)
             self.cursor.execute(sql)
             self.db.commit()
             return server_return.server_success('记录成功')
         except:
             return server_return.server_error(server_return.ERROR_DB)
Пример #17
0
def upload_apk():
    if 'version_code' in request.form and 'version_name' in request.form and 'file' in request.files and _check_sign(
            request.form):
        form = request.form
        is_current = form.get('is_current', 0)
        is_force = form.get('is_force', 0)
        message = form.get('message', None)
        directory = _get_directory()
        file = request.files['file']
        if 'apk' in file.filename:
            print(file, type(file))
            fn = _get_filename(file.filename, directory)
            file.save(directory + '/' + fn)

            client().save_version(file_name=fn, version_code=int(form.get('version_code')),
                                  version_name=form.get('version_name'), is_current=int(is_current),
                                  message=message, is_force=is_force)
            return server_return.server_success({'m': '上传成功'})
        else:
            return server_return.server_error(server_return.ERROR_SIGN, '文件格式有误')
    else:
        return server_return.server_error(server_return.ERROR_SIGN)
Пример #18
0
 def mark_movie(self, imei, movie_id, movie_name, downloaded_time,
                downloaded_timestamp):
     select_url = "select * from {table} where imei = \"{imei}\";".format(
         table=TABLE_USER, imei=imei)
     self.cursor.execute(select_url)
     user = self.cursor.fetchone()
     if user:
         user_id = user[INDEX_ID]
         user_name = user[INDEX_NAME]
         sql = 'insert into {table}(userId,userName,movieId,movieName,downloaded_time,' \
               'downloaded_timestamp) values({userId},\"{userName}\",{movieId},\"{movieName}\",\"{downloaded_time}\",' \
               '{downloaded_timestamp});'.format(table=TABLE_USER_MOVIE, userId=user_id, userName=user_name,
                                                 movieId=movie_id, movieName=movie_name,
                                                 downloaded_time=downloaded_time,
                                                 downloaded_timestamp=downloaded_timestamp)
         try:
             print('记录数据', sql)
             self.cursor.execute(sql)
             self.db.commit()
             return server_return.server_success('记录成功')
         except:
             return server_return.server_error(server_return.ERROR_DB)
Пример #19
0
def maoyan_board():
    sign = request.args.get('sign', None)
    tag = request.args.get('tag', 0)
    page_num = request.args.get('page_num', 1)
    page_size = request.args.get('page_size', 10)
    time_stamp = request.args.get('time_stamp', 0)

    print(time_stamp, int(time.time()))
    if sign and time_stamp:
        hl = md5()
        hl.update(('我是大帅哥' + time_stamp).encode(encoding='utf-8'))
        mm = hl.hexdigest()
        print('sign:{sign},mm:{mm}'.format(sign=sign, mm=mm))
        if sign == mm:
            j = get_maoyan_control().get_data(tag=tag,
                                              page_num=page_num,
                                              page_size=page_size)
            return server_return.server_success(j)
        else:
            return server_return.server_error(server_return.ERROR_PARAMS)
    else:
        return server_return.server_error(server_return.ERROR_PARAMS)
Пример #20
0
 def create_user(self, root_imei, imei, role, usable, name):
     """
     创建/更新用户(更新时,只改变role,name和usable字段)
     :param root_imei:
     :param imei:
     :param role:
     :param usable:
     :param name:
     :return:
     """
     self.cursor.execute('select role from {table} where imei = {imei};'.format(table=TABLE_USER, imei=root_imei))
     # root_role = self.cursor.fetchone()
     # print(type(root_role), root_role)
     if self.cursor.fetchone()[0] == 'root':
         count_sql = 'select count(*) from user where imei = "{imei}";'.format(imei=imei)
         self.cursor.execute(count_sql)
         if self.cursor.fetchone()[0] == 0:
             # 插入新用户
             return self._save_new_normal_user(imei, root_imei, usable, name)
         else:
             # 更新 只改变role,name和usable字段
             self.cursor.execute('select * from user where imei = "{imei}";'.format(imei=imei))
             user = self.cursor.fetchone()
             print('更新 select')
             print(user)
             _role = user[3] if role is None else role
             _usable = user[5] if usable is None else usable
             # _name = '' if name is None else name
             update_sql = 'update {table} set role=\"{role}\",usable={usable},name=\"{name}\" where imei ={imei};' \
                 .format(table=TABLE_USER, role=_role, imei=imei, usable=_usable, name=name)
             try:
                 print('更新', update_sql)
                 self.cursor.execute(update_sql)
                 self.db.commit()
                 return server_return.server_success('更新成功')
             except:
                 return server_return.server_error(server_return.ERROR_DB)
     else:
         return server_return.server_error(ERROR_PERMISSION_DE)
Пример #21
0
    def mark_in(self, imei, login_time, local, ip, version_code, version_name):
        select_sql = 'select * from {table} where imei = {imei}' \
            .format(table=TABLE_USER, imei=imei)
        self.cursor.execute(select_sql)
        user = self.cursor.fetchone()
        if user:
            user_id = user[INDEX_ID]
            username = user[INDEX_NAME]
            values_str = ' values({user_id},\"{imei}\",\"{login_time}\"' \
                .format(user_id=user_id, imei=imei, login_time=login_time)
            insert_sql = 'insert into {table}(user_id,imei,login_time'.format(table=TABLE_USER_LOG)
            if username:
                insert_sql += ',username'
                values_str += ',\"{username}\"'.format(username=username)
            if local:
                insert_sql += ',local'
                values_str += ',\"{local}\"'.format(local=local)
            if ip:
                insert_sql += ',ip'
                values_str += ',\"{ip}\"'.format(ip=ip)
            if version_code:
                insert_sql += ',version_code'
                values_str += ',{version_code}'.format(version_code=version_code)
            if version_name:
                insert_sql += ',version_name'
                values_str += ',\"{version_name}\"'.format(version_name=version_name)
            f_insert_sql = insert_sql + ')' + values_str + ');'

            print('mark_in', f_insert_sql)

            try:
                self.cursor.execute(f_insert_sql)
                lastrowid = self.cursor.lastrowid
                self.db.commit()
                return server_return.server_success({'mark_id': lastrowid})
            except:
                return server_return.server_error(server_return.ERROR_DB)
        else:
            return server_return.server_error(server_return.ERROR_DB, '用户不存在')
Пример #22
0
 def mark_in_ip(self, ip, mark_id):
     local = None
     try:
         res = requests.get(
             'http://ip.zxinc.org/ipquery/?ip={ip}'.format(ip=ip))
         selector = Selector(text=res.text)
         local = selector.xpath(
             '//form[@method="get"]//tr[4]/td[2]/text()').extract_first()
     except:
         pass
     sets = 'ip=\"{ip}\"'.format(ip=ip)
     if local:
         sets += ',local=\"{local}\"'.format(local=local)
     update_sql = 'update {table} set {sets} where id = {mark_id}'.format(
         table=TABLE_USER_LOG, sets=sets, mark_id=mark_id)
     print('update_sql', update_sql)
     try:
         self.cursor.execute(update_sql)
         self.db.commit()
         return server_return.server_success('更新成功')
     except:
         return server_return.server_error(server_return.ERROR_DB,
                                           update_sql)
Пример #23
0
 def _save_new_user(self, imei, role, usable, name):
     """
     插入新用户(普通)
     :param imei:
     :param role:
     :param usable:
     :param name:
     :return: json
     """
     print('插入新用户')
     now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
     _name = '' if name is None else name
     _usable = 1 if usable is None else usable
     _role = 'normal' if role is None else role
     sql = 'insert into {table}(imei,role,create_time,name,usable) values (\"{imei}\",\"{role}\",\"{create_time}\",\"{name}\",\"{usable}\");' \
         .format(table=TABLE_USER, role=_role, imei=imei, create_time=now, name=_name, usable=_usable)
     try:
         # print('插入新用户', sql)
         self.cursor.execute(sql)
         self.db.commit()
         return server_return.server_success('插入成功')
     except:
         return server_return.server_error(server_return.ERROR_DB)
Пример #24
0
 def _save_new_user(self, imei, role, usable, name):
     """
     插入新用户(普通)
     :param imei:
     :param role:
     :param usable:
     :param name:
     :return: json
     """
     print('插入新用户')
     now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
     _name = '' if name is None else name
     _usable = 1 if usable is None else usable
     _role = 'normal' if role is None else role
     sql = 'insert into {table}(imei,role,create_time,name,usable) values (\"{imei}\",\"{role}\",\"{create_time}\",\"{name}\",\"{usable}\");' \
         .format(table=TABLE_USER, role=_role, imei=imei, create_time=now, name=_name, usable=_usable)
     try:
         # print('插入新用户', sql)
         self.cursor.execute(sql)
         self.db.commit()
         return server_return.server_success('插入成功')
     except:
         return server_return.server_error(server_return.ERROR_DB)