def setUp(self): self.dao_wrapper = models.DAOWrapper(os.environ['DB_USER'], os.environ['DB_PASSWORD'], os.environ['DB_HOST'], os.environ['DB_PORT'], CourseTest) # Assuming insert works properly models.insert_courses_from_dict(self.dao_wrapper, COURSE_DICT)
import os import re import typing from flask import Flask, jsonify, render_template, request import models app = Flask(__name__) if os.environ.get("DEV") is not None: dao_wrapper = models.DAOWrapper( os.environ["DB_USER"], os.environ["DB_PASSWORD"], os.environ["DB_HOST"], os.environ["DB_PORT"], "dev", models.CourseDev, models.LogDev, ) print("DEV environment variable detected! Running in development mode") else: dao_wrapper = models.DAOWrapper(os.environ["DB_USER"], os.environ["DB_PASSWORD"], os.environ["DB_HOST"], os.environ["DB_PORT"], os.environ.get("ENV", "heroku")) PATTERN_GET_COURSE_CODE = re.compile(r"c\d+") API_URL = os.environ["UBCAPI_URL"]
import os import re import typing from flask import Flask, jsonify, render_template, request # from flask_sslify import SSLify import models app = Flask(__name__) # sslify = SSLify(app) dao_wrapper = models.DAOWrapper(os.environ['DB_USER'], os.environ['DB_PASSWORD'], os.environ['DB_HOST'], os.environ['DB_PORT']) pattern_course = re.compile(r'c\d+') API_STATUS = 'ONLINE' API_URL = 'https://raw.githubusercontent.com/csianglim/ubcapi/master/data/courses.json' VERSION = '1.2' VERSION_KEY = 'version_key' DIGEST_KEY = 'digest_key' @app.route('/course/<string:course_code>', methods=['GET']) def get_course(course_code): course: models.Course = dao_wrapper.get(course_code) if course is not None: return jsonify({'code': course.code, 'name': course.name})