Example #1
0
    def post_followup(self,
                      course_id,
                      followup_text,
                      cid=None,
                      content_id=None,
                      resolved=True):
        """
    Posts content to a piazza followup. Must provide either cid or content_id.
    """
        if not cid:
            cid = self.get_raw_content(content_id, course_id)['result']['id']
        post_url = (
            'https://piazza.com/logic/api?method=content.create&aid=%s' %
            get_aid())
        post_data = (
            '{"method":"content.create",' +
            '"params":{"content":"","type":"followup","revision":0,' +
            '"anonymous":"no","nid":"%s","subject":"%s","cid":"%s"}}' %
            (course_id, followup_text, cid))
        post_data = post_data.encode('ascii', 'ignore')
        followup_json = json.loads(
            self.url_opener.open(post_url, post_data).read())
        if not followup_json['result']:
            return
        followup_cid = followup_json['result']['id']

        if resolved:
            post_url = (
                'https://piazza.com/logic/api?method=content.mark_resolved&aid=%s'
                % get_aid())
            post_data = (
                '{"method":"content.mark_resolved",' +
                '"params":{"cid":"%s","resolved":true}}' % followup_cid)
            self.url_opener.open(post_url, post_data).read()
Example #2
0
  def post_followup(self, course_id, followup_text, cid=None, content_id=None,
                    resolved=True):
    """
    Posts content to a piazza followup. Must provide either cid or content_id.
    """
    if not cid:
      cid = self.get_raw_content(content_id, course_id)['result']['id']
    post_url = ('https://piazza.com/logic/api?method=content.create&aid=%s'
                % get_aid())
    post_data = ('{"method":"content.create",' +
                 '"params":{"content":"","type":"followup","revision":0,' + 
                 '"anonymous":"no","nid":"%s","subject":"%s","cid":"%s"}}'
                 % (course_id,followup_text,cid))
    post_data = post_data.encode('ascii', 'ignore')
    followup_json = json.loads(self.url_opener.open(post_url, post_data).read())
    if not followup_json['result']:
      return
    followup_cid = followup_json['result']['id']

    if resolved:
      post_url = (
        'https://piazza.com/logic/api?method=content.mark_resolved&aid=%s'
        % get_aid())
      post_data = ('{"method":"content.mark_resolved",' +
                   '"params":{"cid":"%s","resolved":true}}' % followup_cid)
      self.url_opener.open(post_url, post_data).read()
Example #3
0
 def post_followup_comment(self, course_id, comment_text, cid):
   """
   Posts a comment to an existing followup.
   """
   post_url = ('https://piazza.com/logic/api?method=content.create&aid=%s'
               % get_aid())
   post_data = ('{"method":"content.create",' +
                '"params":{"content":"","type":"feedback","revision":0,' + 
                '"anonymous":"no","nid":"%s","subject":"%s","cid":"%s"}}'
                % (course_id,comment_text,cid))
   post_data = post_data.encode('ascii', 'ignore')
   self.url_opener.open(post_url, post_data).read()
Example #4
0
 def post_followup_comment(self, course_id, comment_text, cid):
     """
 Posts a comment to an existing followup.
 """
     post_url = (
         'https://piazza.com/logic/api?method=content.create&aid=%s' %
         get_aid())
     post_data = (
         '{"method":"content.create",' +
         '"params":{"content":"","type":"feedback","revision":0,' +
         '"anonymous":"no","nid":"%s","subject":"%s","cid":"%s"}}' %
         (course_id, comment_text, cid))
     post_data = post_data.encode('ascii', 'ignore')
     self.url_opener.open(post_url, post_data).read()
Example #5
0
 def post_answer(self, course_id, answer_text, answer_type, cid=None,
                         content_id=None):
   """
   Posts content to piazza. Should be used to post an answer to piazza.
   Must provide either cid or content_id.
   """
   if not cid:
     cid = self.get_raw_content(content_id, course_id)['result']['id']
   post_url = ('https://piazza.com/logic/api?method=content.answer&aid=%s'
               % get_aid())
   post_data = ('{"method":"content.answer","params":{"content":"%s",' + 
                '"type":"%s","cid":"%s","revision":0,"anonymous":"no"}}'
                % (answer_text, answer_type, cid))
   self.url_opener.open(post_url, post_data).read()
Example #6
0
 def post_answer(self,
                 course_id,
                 answer_text,
                 answer_type,
                 cid=None,
                 content_id=None):
     """
 Posts content to piazza. Should be used to post an answer to piazza.
 Must provide either cid or content_id.
 """
     if not cid:
         cid = self.get_raw_content(content_id, course_id)['result']['id']
     post_url = (
         'https://piazza.com/logic/api?method=content.answer&aid=%s' %
         get_aid())
     post_data = ('{"method":"content.answer","params":{"content":"%s",' +
                  '"type":"%s","cid":"%s","revision":0,"anonymous":"no"}}' %
                  (answer_text, answer_type, cid))
     self.url_opener.open(post_url, post_data).read()