Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fetch up_vote_count, down_vote_count and view_count from user? #65

Closed
andregasser opened this issue Nov 1, 2017 · 2 comments
Closed

Comments

@andregasser
Copy link

First things first: Thank you very much for your efforts in building this Python package. It saves me lots of hours for sure. Keep up the good work.

Nevertheless, I have a small issue when fetching data from the Stackoverflow site. I try to load a specific user object and would like to get reputation as well as up vote count, down vote count and view count. Fetching reputation works well, but when I try to access the other attributes, such as up_vote_count, I fail.

Here is my code so far:

    so = stackexchange.Site(stackexchange.StackOverflow)
    so_user_obj = so.user(so_user_id)
    so_user_obj.badges.fetch()
    so_user_obj.questions.fetch()
    so_user_obj.answers.fetch()
    user_dict['reputation'] = so_user_obj.reputation
    user_dict['questions_asked'] = len(so_user_obj.questions)
    user_dict['answers_posted'] = len(so_user_obj.answers)
    user_dict['badges_earned'] = len(so_user_obj.badges)
    user_dict['up_votes_received'] = so_user_obj.up_vote_count
    user_dict['down_votes_received'] = so_user_obj.down_vote_count
    user_dict['profile_views'] = so_user_obj.view_count

When running the code, I can fetch reputation successfully, but get this error for the other attribute:

    Traceback (most recent call last):
      File "./stacktrack.py", line 405, in <module>
        user_data = so_get_user_obj_as_dict(so_user_obj)
      File "./stacktrack.py", line 193, in so_get_user_obj_as_dict
        user_dict['up_votes_received'] = so_user_obj.up_vote_count
    AttributeError: 'User' object has no attribute 'up_vote_count'

I actually thought, that up_vote_count, down_vote_count and view_count are part of the response, because of this code in models.py (~ line 342):

    class User(JSONModel):
        """Describes a user on a StackExchange site."""
        transfer = ('display_name', 'profile_image', 'age', 'website_url',
            'location', 'about_me', 'view_count', 'up_vote_count',
            'down_vote_count', 'account_id', 'profile_image',
            ('creation_date', UNIXTimestamp),
            ('last_access_date', UNIXTimestamp),
            ('reputation', FormattedReputation),
            ...

What am I doing wrong here?

I use Python 3.4.3 with py-stackexchange 2.2.7 (installed via pip3).

Any help highly appreciated!

Thank you
André

@andregasser
Copy link
Author

This is also described on StackApps: https://stackapps.com/a/7649/49901 (sorry, for cross-posting, but didn't know where you look for / answer issues with the wrapper. ;-)

@andregasser
Copy link
Author

Hi, I was finally able to solve it myself. See this link:
https://stackapps.com/a/7650/49901

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant