Skip to content

Commit

Permalink
pg courses fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayahhhmed committed Nov 16, 2024
1 parent 34d7e12 commit 4624258
Show file tree
Hide file tree
Showing 9 changed files with 68,612 additions and 58,061 deletions.
70,384 changes: 35,192 additions & 35,192 deletions classes.json

Large diffs are not rendered by default.

12,347 changes: 11,447 additions & 900 deletions courses.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions sql/Classes/up.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TYPE status_enum AS ENUM ('Open', 'Closed', 'Full', 'On Hold');
CREATE TABLE Classes (
"class_id" VARCHAR(255) PRIMARY KEY,
-- "career" VARCHAR(255),
"course_id" VARCHAR(8) NOT NULL,
"career" VARCHAR(255),
"course_id" VARCHAR(255) NOT NULL,
"section" VARCHAR(255) NOT NULL,
"term" VARCHAR(50) NOT NULL,
"year" VARCHAR(4) NOT NULL,
Expand All @@ -15,5 +15,5 @@ CREATE TABLE Classes (
"consent" VARCHAR(255) NOT NULL,
"mode" VARCHAR(255) NOT NULL,
"class_notes" TEXT,
FOREIGN KEY (course_id) REFERENCES Courses(course_code) ON DELETE CASCADE
FOREIGN KEY ("course_id") REFERENCES Courses("course_id") ON DELETE CASCADE
);
2 changes: 1 addition & 1 deletion sql/Courses/up.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CREATE TABLE Courses (
"course_id" VARCHAR(255) PRIMARY KEY,
"course_code" VARCHAR(8), --id
"course_name" VARCHAR(255) NOT NULL,
"uoc" INT NOT NULL,
Expand All @@ -8,5 +9,4 @@ CREATE TABLE Courses (
"career" VARCHAR(255),
"terms" TEXT,
"modes" VARCHAR(255)[]
PRIMARY KEY ("course_code", "career")
);
3 changes: 2 additions & 1 deletion sql/Times/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ CREATE TABLE Times (
"location" VARCHAR(255) NOT NULL,
"time" VARCHAR(100) NOT NULL,
"weeks" VARCHAR(100) NOT NULL,
FOREIGN KEY (class_id) REFERENCES Classes(class_id) ON DELETE CASCADE
"career" VARCHAR(255),
FOREIGN KEY ("class_id") REFERENCES Classes("class_id") ON DELETE CASCADE
);
4 changes: 3 additions & 1 deletion src/class_scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{

#[derive(Debug)]
pub struct Course {
pub course_id: String,
pub course_code: String,
pub course_name: String,
pub uoc: i32,
Expand Down Expand Up @@ -80,6 +81,7 @@ impl ClassScraper {
let information_body = document.select(&form_bodies);

let mut course_info = Course {
course_id: self.course_code.clone() + &self.career.clone(),
course_code: self.course_code.clone(),
course_name: self.course_name.clone(),
uoc: self.uoc,
Expand Down Expand Up @@ -157,7 +159,7 @@ impl ClassScraper {

course_info.classes = class_activity_information
.into_par_iter()
.map(|class_data| parse_class_info(class_data, self.course_code.clone(), self.career.clone()))
.map(|class_data| parse_class_info(class_data, self.course_code.clone() + &self.career.clone(), self.career.clone()))
.collect();
let _ = course_info
.classes
Expand Down
2 changes: 1 addition & 1 deletion src/hasuragres_b_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ pub async fn send_batch_data(hdata: &impl HasuragresData) -> Result<(), Box<dyn
let hasuragres_url = env::var("HASURAGRES_URL")?;
let api_key = env::var("HASURAGRES_API_KEY")?;
let client = Client::new();
println!("{:?} {:?}", hasuragres_url, api_key);
println!("Starting to insert into Hasuragres!");
let requests = vec![
BatchInsertRequest {
metadata: Metadata {
table_name: "courses".to_string(),
columns: vec![
"course_id".to_string(),
"course_code".to_string(),
"course_name".to_string(),
"uoc".to_string(),
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fn convert_courses_to_json(course_vec: &mut Vec<Course>) -> Vec<serde_json::Valu
let mut json_courses = Vec::new();
for course in course_vec.iter() {
json_courses.push(json!({
"course_id": course.course_id,
"course_code": course.course_code,
"course_name": course.course_name,
"uoc": course.uoc,
Expand Down
Loading

0 comments on commit 4624258

Please sign in to comment.