Skip to content

Commit

Permalink
watch videos
Browse files Browse the repository at this point in the history
  • Loading branch information
KartikKapur committed Feb 3, 2019
1 parent 2f6b4c6 commit ba1bd06
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
22 changes: 19 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def answer_vitamin(course_ok_id, lecture_url_name, video_index, vitamin_index,
"""Submits the user's answer to a given vitamin and returns if the user got it correct or not."""
user_courses = get_updated_user_courses()
int_course_ok_id = int(course_ok_id)
user_ok_id = get_user_data()["id"]
user_ok_id = get_user_data()["email"]
for course in user_courses:
if course['course_id'] == int_course_ok_id:
vitamin = db[Vitamin.collection].find_one({
Expand All @@ -944,8 +944,8 @@ def answer_vitamin(course_ok_id, lecture_url_name, video_index, vitamin_index,
time = datetime.now()

sql_client.answer_vitamin(user_ok_id, course_ok_id,
vitamin['answer'], video_index,
vitamin_index, lecture_url_name)
vitamin['answer'], lecture_url_name, video_index,
vitamin_index)
submission = request.get_json().get('answer')
if submission == vitamin['answer']:
return jsonify(success=True, message="Correct!"), 200
Expand All @@ -956,3 +956,19 @@ def answer_vitamin(course_ok_id, lecture_url_name, video_index, vitamin_index,
return jsonify(success=False, message="Invalid vitamin"), 404
return jsonify(success=False,
message="Can only answer a vitamin on Hermes for an OK course you are a part of"), 403

@app.route(
'/course/<course_ok_id>/lecture/<lecture_url_name>/video/<int:video_index>/watch_video',
methods=["POST"])
@validate_and_pass_on_ok_id
def watch_video(course_ok_id, lecture_url_name, video_index, ok_id=None):
user_courses = get_updated_user_courses()
int_course_ok_id = int(course_ok_id)
user_ok_id = get_user_data()["email"]
for course in user_courses:
if course['course_id'] == int_course_ok_id:
sql_client.watch_video(user_ok_id, course_ok_id, lecture_url_name,video_index)
eturn jsonify(success=True,
message="Watched Video"), 200
return jsonify(success=False,
message="Can only view a lecture on Hermes for an OK course you are a part of"), 403
22 changes: 8 additions & 14 deletions utils/schemas.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
DEALLOCATE ALL;

CREATE TABLE IF NOT EXISTS attendance (
user_email varchar NOT NULL,
course_ok_id varchar NOT NULL,
lecture_url_name varchar NOT NULL
);

CREATE TABLE IF NOT EXISTS piazza_questions (
user_email varchar NOT NULL,
course_ok_id varchar NOT NULL,
Expand All @@ -17,21 +11,21 @@ CREATE TABLE IF NOT EXISTS piazza_questions (
);

CREATE TABLE IF NOT EXISTS vitamin_answers (
user_ok_id varchar NOT NULL,
user_email varchar NOT NULL,
course_ok_id varchar NOT NULL,
time_answered timestamp NOT NULL,
answer varchar NOT NULL,
lecture_url_name varchar NOT NULL,
video_index integer NOT NULL,
vitamin_index integer NOT NULL,
lecture_url_name varchar NOT NULL
vitamin_index integer NOT NULL
);

CREATE TABLE IF NOT EXISTS videos_watched (
user_ok_id varchar NOT NULL,
user_email varchar NOT NULL,
course_ok_id varchar NOT NULL,
time_watched timestamp NOT NULL,
video_index integer NOT NULL,
lecture_url_name varchar NOT NULL
time_watched timestamp NOT NULL,
lecture_url_name varchar NOT NULL,
video_index integer NOT NULL
);

PREPARE post_question AS
Expand All @@ -44,4 +38,4 @@ PREPARE answer_vitamin as
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, localtimestamp, $3, $4)
14 changes: 7 additions & 7 deletions utils/sql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ 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,answer,
video_index, vitamin_index,lecture_url_name):
def answer_vitamin(self,user_email,course_ok_id,answer,
lecture_url_name, video_index, vitamin_index):
cur = self.conn.cursor()
print("here")

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


def watch_video(self,user_ok_id, course_ok_id,time_watched,video_index, lecture_url_name):
def watch_video(self,user_email, course_ok_id,lecture_url_name, video_index):
cur = self.conn.cursor()
cur.execute(
'EXECUTE watch_video (%s, %s, %s, %s, %s)',
(user_ok_id, course_ok_id,time_watched,video_index, lecture_url_name)
'EXECUTE watch_video (%s, %s, %s, %s)',
(user_email, course_ok_id,lecture_url_name, video_index)
)
self.conn.commit()
cur.close()

0 comments on commit ba1bd06

Please sign in to comment.