2

I'm using Py_Stackexchange to pull data from Stackoverflow for some statistical analysis, and stumbled upon a problem.

I need to retrieve the upvotes and downvotes on an answer. I have the stackexchange.Answer object, and it has a field called 'transfers' which is a tuple of strings like:

'is_accepted', 'locked_date', 'question_id', 'up_vote_count', 'down_vote_count',
'view_count', 'score', 'community_owned', 'title', 'body'

How do I get the actual numerical values corresponding to these fields?

Richard
  • 6,812
  • 5
  • 45
  • 60
Xstatic
  • 1,411
  • 1
  • 11
  • 14
  • Are you using a library to process this, or the raw API responses... as it's in `up_vote_count` and `down_vote_count` - if you've got this far - not quite sure what problem you're trying to address? – Jon Clements Oct 01 '14 at 14:32

1 Answers1

2

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.
André Gasser
  • 1,065
  • 2
  • 14
  • 34
Andy
  • 49,085
  • 60
  • 166
  • 233