Exemplo n.º 1
0
def login_ninjacourses(username, password):
    user = auth.authenticate(username=username, password=password)
    if user:
        return True
    try:
        result_page = fetch_page_after_auth(username=username, password=password, next_url='/')
    except Exception as e:
        print repr(e)
        return False
    UserProfile.get_or_create_user(username=username, password=password)
    return True
Exemplo n.º 2
0
def fetch_course_data(username, password):
    user_schedule_page = _fetch_user_schedule_page(username, password)
    user, user_profile = UserProfile.get_or_create_user(username=username, password=password)
    if user_profile.is_main_schedule_imported:
        return user_profile.course_list
    user_profile.set_main_schedule(course_list)
    return course_list
Exemplo n.º 3
0
def fetch_friend_data(username, password):
    friend_list_page = _fetch_user_friend_list_page(username, password)
    user, user_profile = UserProfile.get_or_create_user(username=username, password=password)
    if user_profile.is_friend_list_imported:
        return user_profile.friend_list
    friend_list = _fetch_friend_list_from_page(friend_list_page)
    user_profile.set_friend_list(friend_list)
    return friend_list 
Exemplo n.º 4
0
def fetch_compare_data(username, password):

    compare_dict = {}
    
    user, user_profile = UserProfile.get_or_create_user(username=username, password=password)

    if not user_profile.is_main_schedule_imported:
        fetch_course_data()
    course_list = user_profile.course_list
    if not user_profile.is_friend_list_imported:
        fetch_friend_data()
    friend_list = [[str(x), x.url_as_friend, _get_course_list(user_profile=x, username=username, password=password)] for x in user_profile.friend.all()]

    for friendly_name, course_id in course_list:
        compare_dict[friendly_name] = []

    for friend_name, friend_url, friend_course_list in friend_list:
        if type(friend_course_list) is list:
            for friendly_name, course_id in friend_course_list:
                if friendly_name in compare_dict:
                    compare_dict[friendly_name].append([friend_name, friend_url])

    return compare_dict.items()