Skip to content

Instantly share code, notes, and snippets.

@JDougherty
Created August 22, 2014 03:19
Show Gist options
  • Save JDougherty/c841e5952f45a1550f32 to your computer and use it in GitHub Desktop.
Save JDougherty/c841e5952f45a1550f32 to your computer and use it in GitHub Desktop.
from piazza_api import PiazzaAPI
import dateutil.parser
p = PiazzaAPI('hv3tfd1v38g7fc')
p.user_auth()
s_answers = 0
i_answers = 0
s_before_i = 0
posts_with_answers = set()
for i in xrange(1, 613):
a = p.get(i)
print a['aid'],":", i
a = a.get('result', None)
if a:
if a.get('children', None) is None:
continue
children = a['children']
s_time = None
i_time = None
for child in children:
if child['type'] == 's_answer':
print " ",child['type'], child['history'][-1]['created']
s_answers += 1
s_time = child['history'][-1]['created']
if child['type'] == 'i_answer':
print " ",child['type'], child['history'][-1]['created']
i_answers += 1
i_time = child['history'][-1]['created']
if s_time and i_time:
s_time = dateutil.parser.parse(s_time)
i_time = dateutil.parser.parse(i_time)
if s_time < i_time:
s_before_i += 1
if s_time or i_time:
posts_with_answers.add(i)
print "Student Answers", s_answers
print "Instructor Answers", i_answers
print "Number of Student Answers before Instructor Answers", s_before_i
print "Number of posts with answers", len(posts_with_answers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment