Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion labconnect/errors/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Response, make_response, render_template
from flask import Response, make_response

from . import error_blueprint

Expand Down
1 change: 0 additions & 1 deletion labconnect/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from enum import Enum as EnumPython

import orjson
Expand Down
2 changes: 0 additions & 2 deletions labconnect/main/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def validate_code_and_get_user_email(code: str) -> tuple[str | None, bool | None

@main_blueprint.get("/login")
def saml_login():

# In testing skip RPI login purely for local development
if current_app.config["TESTING"] and (
current_app.config["FRONTEND_URL"] == "http://localhost:3000"
Expand Down Expand Up @@ -103,7 +102,6 @@ def saml_callback():

@main_blueprint.post("/register")
def registerUser():

# Gather the new user's information
json_data = request.get_json()
if not json_data:
Expand Down
2 changes: 0 additions & 2 deletions labconnect/main/discover_routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from flask_jwt_extended import get_jwt_identity, jwt_required

from labconnect import db
from labconnect.models import (
ClassYears,
Expand Down
8 changes: 3 additions & 5 deletions labconnect/main/opportunity_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def packageIndividualOpportunity(opportunityInfo):


def packageOpportunityCard(opportunity):

# get professor and department by getting Leads and LabManager
query = db.session.execute(
db.select(Leads, LabManager, User.first_name, User.last_name)
Expand Down Expand Up @@ -498,7 +497,6 @@ def getOpportunityCards():

@main_blueprint.get("/staff/opportunities/<string:rcs_id>")
def getLabManagerOpportunityCards(rcs_id: str) -> list[dict[str, str]]:

query = (
db.select(
Opportunities.id,
Expand Down Expand Up @@ -535,7 +533,6 @@ def getLabManagerOpportunityCards(rcs_id: str) -> list[dict[str, str]]:

@main_blueprint.get("/profile/opportunities/<string:rcs_id>")
def getProfileOpportunities(rcs_id: str) -> list[dict[str, str]]:

query = (
db.select(
Opportunities.id,
Expand Down Expand Up @@ -770,7 +767,9 @@ def editOpportunity_get(opportunity_id):
"type": (
"Any"
if len(credits) > 0 and opportunity.pay and opportunity.pay > 0
else "For Pay" if opportunity.pay and opportunity.pay > 0 else "For Credit"
else "For Pay"
if opportunity.pay and opportunity.pay > 0
else "For Credit"
),
"hourlyPay": str(opportunity.pay),
"credits": credits,
Expand All @@ -792,7 +791,6 @@ def editOpportunity_get(opportunity_id):
@main_blueprint.put("/editOpportunity/<int:opportunity_id>")
@jwt_required()
def editOpportunity(opportunity_id):

user_id = get_jwt_identity()
if not request.data or not user_id:
abort(400)
Expand Down
5 changes: 0 additions & 5 deletions labconnect/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def departmentCards():

@main_blueprint.get("/departments/<string:department>")
def departmentDetails(department: str):

department_data = db.session.execute(
db.select(
RPIDepartments.id,
Expand Down Expand Up @@ -92,7 +91,6 @@ def departmentDetails(department: str):
@main_blueprint.get("/profile")
@jwt_required()
def profile():

user_id = get_jwt_identity()

data = db.session.execute(
Expand Down Expand Up @@ -133,7 +131,6 @@ def profile():
@main_blueprint.get("/staff/<string:id>")
@jwt_required()
def getProfessorProfile(id: str):

data = db.session.execute(
db.select(
User.preferred_name,
Expand Down Expand Up @@ -208,7 +205,6 @@ def force_error():

@main_blueprint.get("/majors")
def majors() -> list[dict[str, str]]:

data = db.session.execute(db.select(Majors).order_by(Majors.code)).scalars()

if not data:
Expand All @@ -224,7 +220,6 @@ def majors() -> list[dict[str, str]]:

@main_blueprint.get("/years")
def years() -> list[int]:

data = db.session.execute(
db.select(ClassYears)
.order_by(ClassYears.class_year)
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/4dd3611b273e_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
Expand Down
2 changes: 1 addition & 1 deletion migrations/versions/55928fddcb12_initial_migration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Initial migration.

Revision ID: 55928fddcb12
Revises:
Revises:
Create Date: 2024-09-24 16:26:33.004366

"""
Expand Down
1 change: 0 additions & 1 deletion migrations/versions/f7518ca21f44_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
Expand Down
63 changes: 63 additions & 0 deletions tools/addCourses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys
import requests

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# Import os
import os

basedir = os.path.abspath(os.path.dirname(__file__))

from labconnect.models import Courses


def fetch_json_data(json_url):
response = requests.get(json_url)
if response.status_code == 200:
data = response.json()
return data
else:
print(
f"Failed to fetch JSON data from {json_url}. Status code: {response.status_code}"
)
return None


def insert_courses_from_json(session, courses_data):
for course_code, course_info in courses_data.items():
course_name = course_info.get("name")

existing_course = session.query(Courses).filter_by(code=course_code).first()
if existing_course:
if existing_course.name != course_name:
existing_course.name = course_name
session.commit()
print(f"Course '{course_code}' name updated.")
else:
new_course = Courses()
new_course.code = course_code
new_course.name = course_name
session.add(new_course)
session.commit()
print(f"Course '{course_code}' inserted into the database.")


def main():
engine = create_engine(f"sqlite:///{os.path.join(basedir, 'database.db')}")
# TODO: fix this
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()

json_url = "https://github.com/quacs/quacs-data/blob/master/semester_data/202409/catalog.json"
courses_data = fetch_json_data(json_url)
if not courses_data:
sys.exit("Failed to fetch courses data. Exiting...")

insert_courses_from_json(session, courses_data)
session.close()


if __name__ == "__main__":
main()
72 changes: 72 additions & 0 deletions tools/addDept.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import json

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from labconnect.models import (
RPISchools,
RPIDepartments,
) # Import your SQLAlchemy models here

basedir = os.path.abspath(os.path.dirname(__file__))

JSON_FILE_PATH = (
"https://github.com/quacs/quacs-data/blob/master/semester_data/202409/schools.json"
)

ENGINE_URL = f"sqlite:///{os.path.join(basedir, 'database.db')}"

BASE_DIR = os.path.abspath(os.path.dirname(__file__))


def load_json_data(json_file_path):
with open(json_file_path, "r") as file:
data = json.load(file)
return data


def insert_schools_and_departments(session, schools_data):
for school_data in schools_data:
school_name = school_data.get("name")
school_description = ""

school = RPISchools()
school.name = school_name
school.description = school_description
session.add(school)
session.commit()
print(f"School '{school_name}' inserted into the database.")

for department_data in school_data.get("depts", []):
# department_code = department_data.get("code")
department_name = department_data.get("name")
department_description = ""

department = RPIDepartments()
department.name = department_name
department.description = department_description
department.school_id = school_name
session.add(department)
session.commit()
print(f"Department '{department_name}' inserted into the database.")


def main():
engine = create_engine(f"sqlite:///{os.path.join(basedir, 'database.db')}")
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()

schools_data = load_json_data(JSON_FILE_PATH)
if not schools_data:
print("Failed to load JSON data. Exiting...")
return

insert_schools_and_departments(session, schools_data)

session.close()


if __name__ == "__main__":
main()
Loading