Skip to content

Commit

Permalink
style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KartikKapur committed Jan 28, 2019
1 parent bcc2239 commit 03f281f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
26 changes: 17 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,18 +541,21 @@ def create_piazza_bot(course_ok_id, ok_id=None):
piazza_master_post_id = request.form['piazza_master_post_id']

if piazza_master_post_id: # A Master post has already been created
Course.update_course(course_ok_id, db,piazza_active="active")
Course.update_course(course_ok_id, db,
piazza_active="active")
if Piazza.post_exists(post_id=piazza_master_post_id,
piazza_course_id=piazza_course_id):
piazza_course_id=piazza_course_id):
Piazza.pin_post(post_id=piazza_master_post_id,
piazza_course_id=piazza_course_id)
Piazza.add_unadded_lectures(piazza_course_id, piazza_master_post_id, db, course_ok_id)
Piazza.add_unadded_lectures(piazza_course_id,
piazza_master_post_id, db,
course_ok_id)
Piazza.recreate_master_post(
master_id=piazza_master_post_id,
course_ok_id=course_ok_id,
piazza_course_id=piazza_course_id,
db=db
)
)
return jsonify(success=True), 200
try:
master_post = Piazza.create_master_post(
Expand All @@ -561,7 +564,9 @@ def create_piazza_bot(course_ok_id, ok_id=None):
)
master_id = master_post["nr"]

Piazza.add_unadded_lectures(piazza_course_id, piazza_master_post_id, db, course_ok_id)
Piazza.add_unadded_lectures(piazza_course_id,
piazza_master_post_id, db,
course_ok_id)
Piazza.recreate_master_post(master_id=master_id,
course_ok_id=course_ok_id,
piazza_course_id=piazza_course_id,
Expand Down Expand Up @@ -608,7 +613,8 @@ def ask_piazza_question(course_ok_id, lecture_url_name, video_index,
data = get_user_data()
name = data["name"]
email = data["email"]
if piazza.post_exists(post_id=request.form["piazza_lecture_post_id"],
if piazza.post_exists(
post_id=request.form["piazza_lecture_post_id"],
piazza_course_id=request.form["piazza_course_id"]):
identity_msg = "posted on behalf of " + name
post_id = Piazza.create_followup_question(
Expand Down Expand Up @@ -654,8 +660,8 @@ def disable_piazza(course_ok_id, ok_id=None):
}
)
if Piazza.post_exists(post_id=request.form["piazza_master_post_id"],
piazza_course_id=request.form[
"piazza_course_id"]):
piazza_course_id=request.form[
"piazza_course_id"]):
Piazza.unpin_post(post_id=request.form["piazza_master_post_id"],
piazza_course_id=request.form[
"piazza_course_id"])
Expand Down Expand Up @@ -847,7 +853,9 @@ def answer_vitamin(course_ok_id, lecture_url_name, video_index, vitamin_index,
if vitamin:
time = datetime.now()

sql_client.answer_vitamin(user_ok_id, course_ok_id, time.strftime("%Y-%m-%d %H:%M:%S"), vitamin['answer'], video_index, vitamin_index, lecture_url_name)
sql_client.answer_vitamin(user_ok_id, course_ok_id,
vitamin['answer'], video_index,
vitamin_index, lecture_url_name)
submission = request.get_json().get('answer')
if submission == vitamin['answer']:
return jsonify(success=True, message="Correct!"), 200
Expand Down
20 changes: 13 additions & 7 deletions utils/piazza_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def create_master_post(content="", network=None, piazza_course_id=None):
return master_post


def create_lecture_post(lecture_title, date,db,master_id,course_ok_id, lecture_url_name,
def create_lecture_post(lecture_title, date, db, master_id, course_ok_id,
lecture_url_name,
network=None, piazza_course_id=None, content=None):
"""
Creates a lecture post on piazza for a given lecture number. Takes in
Expand Down Expand Up @@ -85,7 +86,8 @@ def create_lecture_post(lecture_title, date,db,master_id,course_ok_id, lecture_u


def create_followup_question(lecture_post_id, url, tag, question, network=None,
piazza_course_id=None, identity_msg="posted Anonymously"):
piazza_course_id=None,
identity_msg="posted Anonymously"):
"""Adds a followup question to a given lecture post. Takes in a lecture number,
course id, and contents of a question.
piazza_course_id: (the id in the url)- piazza.com/<piazza_course_id>
Expand Down Expand Up @@ -188,15 +190,15 @@ def recreate_master_post(master_id, course_ok_id, db, network=None,
cid=master_id, content=content)



def pin_post(post_id, network=None, piazza_course_id=None):
if not network:
network = piazza.network(piazza_course_id)
rpc = network._rpc
post = network.get_post(post_id)
post_content = post["history"][0]["content"]
post_content += "<p>#pin</p>"
edit_post(network=network, piazza_course_id=piazza_course_id, cid=post_id, content=post_content)
edit_post(network=network, piazza_course_id=piazza_course_id, cid=post_id,
content=post_content)


def unpin_post(post_id, network=None, piazza_course_id=None):
Expand All @@ -205,7 +207,8 @@ def unpin_post(post_id, network=None, piazza_course_id=None):
rpc = network._rpc
post = network.get_post(post_id)
post_content = post["history"][0]["content"].replace("#pin", "")
edit_post(network=network, piazza_course_id=piazza_course_id, cid=post_id, content=post_content)
edit_post(network=network, piazza_course_id=piazza_course_id, cid=post_id,
content=post_content)


def delete_post(network=None, piazza_course_id=None, cid=None, post_data=None,
Expand All @@ -229,7 +232,9 @@ def delete_post(network=None, piazza_course_id=None, cid=None, post_data=None,
except:
return

def add_unadded_lectures(piazza_course_id, piazza_master_post_id, db,course_ok_id):

def add_unadded_lectures(piazza_course_id, piazza_master_post_id, db,
course_ok_id):
not_on_piazza_db_obj = db[Lecture.collection].find({
"lecture_piazza_id": "",
"course_ok_id": course_ok_id
Expand All @@ -246,7 +251,8 @@ def add_unadded_lectures(piazza_course_id, piazza_master_post_id, db,course_ok_i
db=db
)

def post_exists(post_id, network=None, piazza_course_id = None):

def post_exists(post_id, network=None, piazza_course_id=None):
try:
if not network:
network = piazza.network(piazza_course_id)
Expand Down
4 changes: 2 additions & 2 deletions utils/schemas.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ PREPARE retrieve_questions_for_timestamp as
SELECT * FROM piazza_questions WHERE seconds >= $1 AND seconds <= $2 AND course_ok_id=($3) AND lecture_url_name=($4) AND video_index=($5);

PREPARE answer_vitamin as
INSERT INTO vitamin_answers VALUES ($1, $2, $3, $4, $5, $6, $7);
INSERT INTO vitamin_answers VALUES ($1, $2, localtimestamp, $3, $4, $5, $6);

PREPARE watch_video as
INSERT INTO videos_watched VALUES ($1, $2, $3, $4, $5);
INSERT INTO videos_watched VALUES ($1, $2, $3, $4, $5)
8 changes: 4 additions & 4 deletions utils/sql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def retrieve_questions_for_timestamp(self, start_second, end_second, course_ok_i
cur.close()
return rows

def answer_vitamin(self,user_ok_id,course_ok_id, time_answered,answer,
def answer_vitamin(self,user_ok_id,course_ok_id,answer,
video_index, vitamin_index,lecture_url_name):
cur = self.conn.cursor()
print("here")

cur.execute(
'EXECUTE answer_vitamin (%s, %s, %s, %s, %s, %s, %s)',
(user_ok_id, course_ok_id, time_answered, answer,video_index,
'EXECUTE answer_vitamin (%s, %s, %s, %s, %s, %s)',
(user_ok_id, course_ok_id, answer,video_index,
vitamin_index, lecture_url_name)
)
self.conn.commit()
Expand Down

0 comments on commit 03f281f

Please sign in to comment.