예제 #1
0
 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)
예제 #2
0
파일: app.py 프로젝트: LynxHack/ubcapi
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"]
예제 #3
0
파일: app.py 프로젝트: csianglim/ubcapi
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})