I utilized the question demo, provided by Py-Stackexchange for this answer.
The biggest thing you need to do is ensure that your filter includes the up_vote_count
and down_vote_count
attributes.
Once you have this filter, you can access the value by question.up_vote_count
(or answer.up_vote_count
if you are checking an answer).
As an example, I modified line 22 in the demo, to include these two attributes in the filter:
question = site.question(id, filter="!b0OfMwwD.s*79x")
Filters can be created here.
Then I added this line at the very end of the script:
print('%d Upvotes.' % question.up_vote_count)
When I run it against this question, I get this output:
Please enter an API key if you have one (Return for none):
Enter a question ID: 26143702
--- Getting the upvotes of an answer using Py-Stackexchange ---
<p>I'm using <code>Py_Stackexchange</code> to pull data from <code>Stackoverflow</code> for some statistical analysis, and stumbled upon a problem.</p>
<p>I need to retrieve the upvotes and downvotes on an answer. I have the <code>stackexchange.Answer</code> object, and it has a field called 'transfers' which is a tuple of strings like:</p>
<pre><code>'is_accepted', 'locked_date', 'question_id', 'up_vote_count', 'down_vote_count',
'view_count', 'score', 'community_owned', 'title', 'body'
</code></pre>
<p>How do I get the actual numerical values corresponding to these fields?</p>
0 answers.
1 Upvotes.