def displey_user_profile(con, signed_in, user, user_following, user_ignoring): '''Display user profile''' following_query = userdata.following_iter(con, signed_in) ignoring_query = userdata.ignoring_iter(con, signed_in) following_list = (i[0] for i in following_query) ignoring_list = (i[0] for i in ignoring_query) print('\n=====\n') if user.user_id in following_list: print(f'Username: {user.username.title()} - Following') elif user.user_id in ignoring_list: print(f'Username: {user.username.title()} - Ignoring') else: print(f'Username: {user.username.title()}') print(f'Location: {user.location}\n') # print(f'Bio: {user.biography}') print('Following: ') if user_following: for followed_user in user_following: print(f'\t{followed_user.title()}') else: print('\tNot following any users.') print('Ignoring: ') if user_ignoring: for followed_user in user_ignoring: print(f'\t{followed_user.title()}') else: print('\tNot ignoring any users') print('\n=====\n')
def display_users(con, signed_in, page_num): '''Display users and user relations''' following_query = userdata.following_iter(con, signed_in) ignoring_query = userdata.ignoring_iter(con, signed_in) following_list = [i[0] for i in following_query] ignoring_list = [i[0] for i in ignoring_query] user_query = userdata.user_iter(con) if page_num > 0: start = 15 * (page_num - 1) end = 15 * page_num user_query_gen = (row for row in user_query) # Generator out of iterable results = itertools.islice(user_query_gen, start, end) query = list(results) if not query: print('\n=====\n') print(f'No posts on page {page_num}. Please go back a page.') print('\n=====\n') else: print('\n=====\n') for user in query: user = Box(dict(user)) if user.user_id in following_list: print(f'{user.username.title()} (following)') elif user.user_id in ignoring_list: print(f'{user.username.title()} (ignoring)') else: print(f'{user.username.title()}') print('\n=====\n')
def display_posts(validated_posts, database_connection, signed_in, page_num, post_id_show=False): """Display posts in a pretty format. Posts are based on page number and and number of posts per page in user timeline. This function uses a generator and islice from itertools to return a slice of posts per page. """ following_query = userdata.following_iter(database_connection, signed_in) following_list = [i[0] for i in following_query] results_page = page_number_display('posts', validated_posts, signed_in, page_num) if not results_page: print('-' * 100) print(f'No posts on page {page_num}. Please go back a page.') print('-' * 100) else: print('-' * 100) for row in results_page: post = Box(dict(row)) if post.user_id in following_list: print(f'|\n|*{post.username.title()}\n|\t\t{post.text}\n|') else: print(f'|\n|{post.username.title()}\n|\t\t{post.text}\n|') if post_id_show: print(f'|Post ID: {post.post_id}') print(f'|\n|\t\t\t\t\t\t\t\t\t\t{post.timestamp[:10]}') print('-' * 100)
def user_following_ignoring(database_connection, user, index=0, to_list=False): """Return list of users being followed or ignored by specified user""" following_query = userdata.following_iter(database_connection, user) ignoring_query = userdata.ignoring_iter(database_connection, user) if to_list: following_list = [i[index] for i in following_query] ignoring_list = [i[index] for i in ignoring_query] return following_list, ignoring_list following_list = (i[index] for i in following_query) ignoring_list = (i[index] for i in ignoring_query) return following_list, ignoring_list
def prompt_for_user_profile(con): '''Return a profile for any user''' while True: print('Enter the username of the user you would like to view') username = input('\t>>> ') c = con.cursor() query = c.execute( '''SELECT * FROM users WHERE username = ?''', (username, )) try: user = [Box(dict(x)) for x in query][0] if user: following_query = userdata.following_iter(con, user) ignoring_query = userdata.ignoring_iter(con, user) following_list = [i[1] for i in following_query] ignoring_list = [i[1] for i in ignoring_query] return user, following_list, ignoring_list except: print('Something went wrong. Maybe this user does not exist?') continue
def display_posts(query, con, signed_in, page_num, post_id_show=False): '''Display posts in a pretty format. Posts are based on page number and and number of posts per page in user timeline. This function uses a generator and islice from itertools to return a slice of posts per page. ''' c = con.cursor() following_query = userdata.following_iter(con, signed_in) following_list = [i[0] for i in following_query] if page_num > 0: start_post = signed_in.posts_per_page * (page_num - 1) end_post = signed_in.posts_per_page * page_num query_gen = (row for row in query) # Generator out of iterable results = itertools.islice(query_gen, start_post, end_post) query = list(results) if not query: print('-' * 100) print(f'No posts on page {page_num}. Please go back a page.') print('-' * 100) else: print('-' * 100) for row in query: post = Box(dict(row)) if post.user_id in following_list: print(f'|\n|*{post.username.title()}\n|\t\t{post.text}\n|') else: print(f'|\n|{post.username.title()}\n|\t\t{post.text}\n|') if post_id_show: print(f'|Post ID: {post.post_id}') print(f'|\n|\t\t\t\t\t\t\t\t\t\t{post.timestamp[:10]}') print('-' * 100) c.close()