Exemplo n.º 1
0
def get_dic(acc_id):
    file_name = '%s.json' % str(acc_id)
    file_path = db_handle.db_handle(settings.db_info)
    acc_file = os.path.join(file_path, file_name)
    if os.path.exists(acc_file):
        with open(acc_file, 'r') as f:
            acc_dic = json.loads(f.readlines()[0])
        return acc_dic
    else:
        print('account is not exist...')
        return False
Exemplo n.º 2
0
def mod_file(acc_id, *args):
    #print(args)
    file_name = '%s.json' % str(acc_id)
    file_path = db_handle.db_handle(settings.db_info)
    acc_file = os.path.join(file_path, file_name)
    if os.path.exists(acc_file):
        with open(acc_file, 'r+') as f:
            acc_data = json.loads(f.readlines()[0])
            # print(json.loads(acc_data))
            if type(args[0]) == dict:
                acc_data = args[0]
            else:
                acc_data[args[0][0]] = args[0][1]
            f.seek(0)
            f.truncate()
            f.write(json.dumps(acc_data))
Exemplo n.º 3
0
def s_view(school_obj):
    print('''
    注册
    登录
    ''')
    choice = input('请选择操作:')
    if choice == '注册':
        name = input('姓名:')
        age = input('年龄:')
        sex = input('性别:')
        stu = Student(name, age, sex, school_obj, False)
        stu.regist()
        # db_file = '%s/%s' % (db_handle(settings.db_info), name)
        #
        # with open(db_file, 'wb') as f:
        #     f.write(pickle.dumps(stu))
    if choice == '登录':
        name = input('用户名:')
        userFile = '%s/stu/%s' % (db_handle(settings.db_info), name)
        with open(userFile, 'rb') as f:
            stuInfo = pickle.loads(f.read())
            print(stuInfo['classes_obj'].name)
            stu_obj = Student(stuInfo['name'], stuInfo['age'], stuInfo['sex'],
                              stuInfo['school_obj'], stuInfo['classes_obj'])
        while os.path.isfile(userFile):
            print('''
            交学费
            选择班级
            ''')
            choice = input('请输入你的选择:')
            if choice == '选择班级':
                for classes_obj in school_obj.classes:
                    print(classes_obj.name)
                choice_c = input('>>>')
                for classes_obj in school_obj.classes:
                    if choice_c == classes_obj.name:
                        # print(classes_obj)
                        stu_obj.choice_classes(classes_obj)
            elif choice == '交学费':
                stu_obj.pay()
            elif choice == 'q':
                exit()
            else:
                print('No chioce....')
        else:
            exit('用户未注册')
Exemplo n.º 4
0
def add_user(userIfo):
    '''
    添加用户
    :param userIfo:用户信息 example:'name=Harvey,password=123'
    :return:
    '''
    acc_dic = {
        'id': 1000,
        'name': None,
        'password': None,
        'credit': 15000,
        'balance': 15000,
        'enroll_date': None,
        'expire_date': None,
        'pay_day': 30,
        'status': 0,  # 0 = normal, 1 = locked, 2 = disabled
        'manager': False  # 是否是管理员
    }
    acc_dic['enroll_date'] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
    now = datetime.datetime.now()
    delta = datetime.timedelta(days=3650)
    acc_dic['expire_date'] = (now + delta).strftime('%Y-%m-%d %H:%M:%S')
    file_num = dbrecord.get_file_num()
    acc_dic['id'] = file_num + 1
    print(acc_dic['id'], file_num)
    file_name = '%s.json' % str(acc_dic['id'])
    file_path = db_handle.db_handle(settings.db_info)
    print(file_path, file_name)
    acc_file = os.path.join(file_path, file_name)
    for item in userIfo.strip().split(','):
        i = item.split('=')
        # for i in item.split('='):
        acc_dic[i[0]] = i[1]
    print(acc_file)
    with open(acc_file, 'w') as f:
        f.write(json.dumps(acc_dic))
        f.flush()
    print(acc_dic)
Exemplo n.º 5
0
 def add_stu(self, stu_obj):
     self.student_list.append(stu_obj)
     db_classes = '%s/classes/%s' % (db_handle.db_handle(
         settings.db_info), self.name)
     with open(db_classes, 'ab') as f:
         pickle.dump(self.student_list, f)
Exemplo n.º 6
0
def create_courses(name, price, outline):
    courses_obj = Courses(name, price, outline)
    courses_file = '%s/courses/%s' % (db_handle(settings.db_info), name)
    with open(courses_file, 'wb') as f:
        pickle.dump(courses_obj, f)
    return courses_obj
Exemplo n.º 7
0
def get_file_num():
    f_path = db_handle(db_info)
    file_num = os.listdir(f_path)[0].split('.')[0]
    return int(file_num)
Exemplo n.º 8
0
#Author:Anliu
import json
import random
from core import db_handle
from conf import setting
#ccount =
db_path = db_handle.db_handle(setting.DATABASE)


#print(db_path)
#account_file = "%s" %(db_path)
def account_input(username, password):
    """
    函数功能是账号输入的总接口
    :param username: 用户名
    :param password: 用户密码
    :return: 以元组的形式返回两个值,一个是用户,另一个是密码
    """
    username = input("请输入账号:")
    password = input("请输入密码:")
    return username, password


def account_register():
    """
    函数功能是账号注册
    :return: 如果账号注册成功,则返回0,账号注册失败返回1
    """
    a = account_input("user", "pass")
    _username = a[0]
    _password = a[1]