Пример #1
0
Файл: user.py Проект: ylpb/learn
def download_pay_movie(client):
    while True:
        send_dic = {
            'type': 'get_movie_list',
            'movie_type': 'not_free',
            'cookies': user_info.get('cookies')
        }
        back_dic = common.send_and_back_data(send_dic, client)
        if not back_dic.get('flag'):
            print(back_dic.get('msg'))
            break
        else:
            movie_list = back_dic.get('movie_list')
            for index, movie in enumerate(movie_list):
                print(index, movie)
            choice = input('请输入需要下载的电影编号:').strip()
            if not choice.isdigit():
                print('请输入数字')
                continue
            choice = int(choice)
            if choice not in range(len(movie_list)):
                print('请输入正确的编号')
                continue
            if user_info.get('is_vip'):
                buy_movie = input('尊贵的会员,请确认是否购买此片(y/n)').strip()
                if not buy_movie == 'y':
                    print('支付失败')
                    break
            else:
                buy_movie = input('请确认是否购买此片(y/n)').strip()
                if not buy_movie == 'y':
                    print('支付失败')
                    break

            movie_name = movie_list[choice][0]
            send_dic = {
                'type': 'download_movie',
                'movie_name': movie_name,
                'cookies': user_info.get('cookies'),
                'is_vip': user_info.get('is_vip')
            }
            back_dic = common.send_and_back_data(send_dic, client)
            movie_size = back_dic.get('movie_size')
            movie_path = os.path.join(settings.DOWNLOAD_FILE_PATH, movie_name)
            with open(movie_path, 'wb') as f:
                num = 0
                while num < movie_size:
                    data = client.recv(1024)
                    f.write(data)
                    num += len(data)
            print('下载完成!')
            break
Пример #2
0
def upload_movie(client):
    while True:
        movie_list_path = settings.UPLOAD_FILE_PATH
        movie_list = os.listdir(movie_list_path)
        if not movie_list:
            print('没有可上传的电影')
            break

        for index, movie in enumerate(movie_list):
            print(index, movie)
        choice = input('请选择需要上传的电影(q退出此功能):').strip()
        if choice == 'q':
            break
        if not choice.isdigit():
            print('请输入数字')
            continue
        choice = int(choice)
        if choice not in range(len(movie_list)):
            print('请输入正确的编号')
            continue
        movie_name = movie_list[choice]
        movie_path = os.path.join(movie_list_path, movie_name)
        movie_md5 = common.get_movie_md5(movie_path)
        print(movie_md5)
        movie_size = os.path.getsize(movie_path)

        send_dic = {
            'type': 'check_movie',
            'movie_md5': movie_md5,
            'cookies': user_info.get('cookies')
        }
        back_dic = common.send_and_back_data(send_dic, client)
        if not back_dic.get('flag'):
            print(back_dic.get('msg'))
            break
        print(back_dic.get('msg'))

        about_free = input('请确认是否免费(y/n):')
        is_free = 0
        if about_free == 'y':
            is_free = 1
        send_dic = {
            'type': 'upload_movie',
            'movie_name': movie_name,
            'movie_size': movie_size,
            'movie_md5': movie_md5,
            'is_free': is_free,
            'cookies': user_info.get('cookies')
        }
        back_dic = common.send_and_back_data(send_dic, client, file=movie_path)
        print(back_dic.get('msg'))
        break
Пример #3
0
Файл: user.py Проект: ylpb/learn
def check_notice(client):
    send_dic = {'type': 'check_notice', 'cookies': user_info.get('cookies')}
    back_dic = common.send_and_back_data(send_dic, client)
    if not back_dic.get('flag'):
        print(back_dic.get('msg'))
    else:
        for i in enumerate(back_dic.get('notice_list')):
            print(i)
Пример #4
0
Файл: user.py Проект: ylpb/learn
def buy_vip(client):
    sure_buy = input('请确认是否购买vip(y/n):')
    if sure_buy == 'y':
        send_dic = {
            'type': 'buy_vip',
            'cookies': user_info.get('cookies'),
            'is_vip': 1
        }
        back_dic = common.send_and_back_data(send_dic, client)
        print(back_dic.get('msg'))
Пример #5
0
def issue_notice(client):
    title = input('请输入标题:').strip()
    content = input('请输入内容:').strip()
    send_dic = {
        'type': 'issue_notice',
        'cookies': user_info.get('cookies'),
        'title': title,
        'content': content
    }
    back_dic = common.send_and_back_data(send_dic, client)
    print(back_dic.get('msg'))
Пример #6
0
Файл: user.py Проект: ylpb/learn
def check_movie(client):
    send_dic = {
        'type': 'get_movie_list',
        'cookies': user_info.get('cookies'),
        'movie_type': 'all'
    }
    back_dic = common.send_and_back_data(send_dic, client)
    if not back_dic.get('flag'):
        print(back_dic.get('msg'))

    else:
        for index, movie_name in enumerate(back_dic.get('movie_list')):
            print(index, movie_name)
Пример #7
0
def delete_movie(client):
    while True:
        send_dic = {
            'type': 'get_movie_list',
            'cookies': user_info.get('cookies'),
            'movie_type': 'all'
        }
        back_dic = common.send_and_back_data(send_dic, client)
        if not back_dic.get('flag'):
            print(back_dic.get('msg'))
            break
        else:
            movie_list = back_dic.get('movie_list')
            if not movie_list:
                print('没有可删除的电影')
                break

            for index, movie in enumerate(movie_list):
                print(index, movie)
            choice = input('请选择需要删除的电影(q退出此功能):').strip()
            if choice == 'q':
                break
            if not choice.isdigit():
                print('请输入数字')
                continue
            choice = int(choice)
            if choice not in range(len(movie_list)):
                print('请输入正确的编号')
                continue
            movie_name = movie_list[choice][0]
            send_dic = {
                'type': 'delete_movie',
                'cookies': user_info.get('cookies'),
                'movie_name': movie_name
            }
            back_dic = common.send_and_back_data(send_dic, client)
            print(back_dic.get('msg'))
            break
Пример #8
0
Файл: user.py Проект: ylpb/learn
def login(client):
    while True:
        username = input('请输入用户名:').strip()
        password = input('请输入密码:').strip()

        send_dic = {
            'type': 'login',
            'user_type': 'user',
            'username': username,
            'password': password
        }
        back_dic = common.send_and_back_data(send_dic, client)
        if back_dic.get('flag'):
            user_info['cookies'] = back_dic.get('session')
            user_info['is_vip'] = back_dic.get('is_vip')
            print(back_dic.get('msg'))
            break
        else:
            print(back_dic.get('msg'))
            break
Пример #9
0
Файл: user.py Проект: ylpb/learn
def register(client):
    while True:
        username = input('请输入用户名:').strip()
        password = input('请输入密码:').strip()
        re_password = input('请确认密码:').strip()

        if not password == re_password:
            print('两次密码不一致')
            continue
        send_dic = {
            'type': 'register',
            'user_type': 'user',
            'username': username,
            'password': password
        }
        back_dic = common.send_and_back_data(send_dic, client)
        if back_dic.get('flag'):
            print(back_dic.get('msg'))
            break
        else:
            print(back_dic.get('msg'))