Skip to content

Commit

Permalink
Merge pull request #30 from Hermes-Berkeley-Org/finishvideos
Browse files Browse the repository at this point in the history
Finishvideos
  • Loading branch information
KartikKapur authored Feb 3, 2019
2 parents 4bbe7a4 + 375ec93 commit 850b05f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 25 deletions.
30 changes: 26 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import consts

app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": os.environ.get('HERMES_UI_URL')}})
CORS(app)
app.config.from_object(Config)

client = MongoClient(os.environ.get('MONGODB_URI'))
Expand Down 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,25 @@ 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)
return 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

@app.route(
'/course/<course_ok_id>/lecture/<lecture_url_name>/video/<int:video_index>/watch_video',
methods=["GET"])
@validate_and_pass_on_ok_id
def get_lecture_attendence(course_ok_id, lecture_url_name, video_index, ok_id=None):
return
37 changes: 37 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
python_version: 3

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10

env_variables:
file: ${file(./deploy/private_env)}
MONGODB_URI: file.MONGODB_URI
DATABASE_NAME: private.MONGODB_URI
DEV_TOKEN: private.DEV_TOKEN
CLIENT_ID: private.CLIENT_ID
CLIENT_SECRET: private.CLIENT_SECRET
PIAZZA_EMAIL: private.PIAZZA_EMAIL
PIAZZA_PASSWORD: private.PIAZZA_PASSWORD
SQL_DATABASE_URL: private.SQL_DATABASE_URL

FLASK_APP: app.py
OK_SERVER: https://okpy.org
OK_MODE: authenticate
TESTING_OK_ID: lejRej
TRANSCRIPTION_MODE: api
OAUTHLIB_INSECURE_TRANSPORT: 1
FLASK_DEBUG: 1
HERMES_UI_URL: http://localhost:3000
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)
20 changes: 13 additions & 7 deletions utils/sql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,31 @@ 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()

def get_lecture_attendence(self, user_email, course_ok_id, lecture_url_name):
cur = self.conn.cursor()
cur.execute(
'EXECUTE lecture_attendence(%s, %s,%s,%s)'
)

0 comments on commit 850b05f

Please sign in to comment.