From 700538ad53b3de05f45b4e846ded63540996d152 Mon Sep 17 00:00:00 2001 From: knox root Date: Tue, 8 Aug 2017 15:47:54 +0100 Subject: [PATCH] Update socli.py -line: 711 Check if the tuple userprofile.top_answer_tags.fetch() is empty or not. When a Stackoverflow user didn't answer or ask question, the original code raises an Exception 'except Exception as e'. The new code is more explicit; it clarifies that the user has no answers or questions. --- socli/socli.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/socli/socli.py b/socli/socli.py index e044433..543397f 100644 --- a/socli/socli.py +++ b/socli/socli.py @@ -707,8 +707,15 @@ def userpage(userid): rate = accepted / float(total_questions) * 100 print("\t\t Total Questions Asked: " + str(len(userprofile.questions.fetch()))) print('\t\t Accept rate is: %.2f%%.' % rate) - print('\nMost experienced on %s.' % userprofile.top_answer_tags.fetch()[0].tag_name) - print('Most curious about %s.' % userprofile.top_question_tags.fetch()[0].tag_name) + #check if the user have answers and questions or no. + if userprofile.top_answer_tags.fetch(): + print('\nMost experienced on %s.' % userprofile.top_answer_tags.fetch()[0].tag_name) + else: + print("You have 0 answers") + if userprofile.top_question_tags.fetch(): + print('Most curious about %s.' % userprofile.top_question_tags.fetch()[0].tag_name) + else: + print("You have 0 questions") except urllib.error.URLError: print_fail("Please check your internet connectivity...") exit(1)