Permalink
Browse files

Updated demo and some more user functions.

  • Loading branch information...
1 parent cc25490 commit dee00421dc88817a34e28ae3310a7c409657b6c7 @lucjon committed Feb 14, 2011
Showing with 19 additions and 2 deletions.
  1. +6 −0 demo/experience.py
  2. +13 −2 stackexchange.py
View
@@ -14,3 +14,9 @@
print 'Most experienced on %s.' % user.top_answer_tags.fetch()[0].tag_name
print 'Most curious about %s.' % user.top_question_tags.fetch()[0].tag_name
+
+total_questions = len(user.questions)
+unaccepted_questions = len(user.unaccepted_questions.fetch())
+accepted = total_questions - unaccepted_questions
+rate = accepted / float(total_questions) * 100
+print 'Accept rate is %.2f%%.' % rate
View
@@ -250,15 +250,22 @@ def _extend(self, json, site):
self.reputation = FormattedReputation(json.reputation)
self.questions = StackExchangeLazySequence(Question, json.question_count, site, json.user_questions_url, self._up('questions'))
+ self.no_answers_questions = StackExchangeLazySequence(Question, None, site, 'users/%d/questions/no-answers' % self.id, self._up('no_answers_questions'), 'questions')
+ self.unanswered_questions = StackExchangeLazySequence(Question, None, site, 'users/%d/questions/unanswered' % self.id, self._up('unanswered_questions'), 'questions')
+ self.unaccepted_questions = StackExchangeLazySequence(Question, None, site, 'users/%d/questions/unaccepted' % self.id, self._up('unaccepted_questions'), 'questions')
+ self.favorites = StackExchangeLazySequence(Question, None, site, json.user_favorites_url, self._up('favorites'), 'questions')
+
self.answers = StackExchangeLazySequence(Answer, json.answer_count, site, json.user_answers_url, self._up('answers'))
# Grr, American spellings. Using them for consistency with official API.
- self.favorites = StackExchangeLazySequence(Question, None, site, json.user_favorites_url, self._up('favorites'), 'questions')
self.tags = StackExchangeLazySequence(Tag, None, site, json.user_tags_url, self._up('tags'))
self.badges = StackExchangeLazySequence(Badge, None, site, json.user_badges_url, self._up('badges'))
self.timeline = StackExchangeLazySequence(TimelineEvent, None, site, json.user_timeline_url, self._up('timeline'), 'user_timelines')
+ self.reputation_detail = StackExchangeLazySequence(RepChange, None, site, json.user_reputation_url, self._up('reputation_detail'))
+
self.mentioned = StackExchangeLazySequence(Comment, None, site, json.user_mentioned_url, self._up('mentioned'), 'comments')
self.comments = StackExchangeLazySequence(Comment, None, site, json.user_comments_url, self._up('comments'))
- self.reputation_detail = StackExchangeLazySequence(RepChange, None, site, json.user_reputation_url, self._up('reputation_detail'))
+ self.mentioned = StackExchangeLazySequence(Comment, None, site, 'users/%d/mentioned' % self.id, self._up('mentioned'))
+
self.top_answer_tags = StackExchangeLazySequence(TopTag, None, site, 'users/%d/top-answer-tags' % self.id, self._up('top_answer_tags'), 'top_tags')
self.top_question_tags = StackExchangeLazySequence(TopTag, None, site, 'users/%d/top-question-tags' % self.id, self._up('top_question_tags'), 'top_tags')
@@ -290,6 +297,10 @@ def top_answers_in_tag(self, tag, **kw):
def top_questions_in_tag(self, tag, **kw):
return self.site.build('users/%d/tags/%s/top-questions' % (self.id, self._get_real_tag(tag)), Question, 'questions', kw)
+ def comments_to(self, user, **kw):
+ uid = user.id if isinstance(user, User) else user
+ return self.site.build('users/%d/comments/%d' % (self.id, uid), Comment, 'comments' ,kw)
+
def __unicode__(self):
return 'User %d [%s]' % (self.id, self.display_name)
def __str__(self):

0 comments on commit dee0042

Please sign in to comment.