From bd6624c710c8ab445a9fa29e5aae76e99d7c88c1 Mon Sep 17 00:00:00 2001 From: 3eef8a28f26fb2bcc514e6f1938929a1f931762 <116031952+3eef8a28f26fb2bcc514e6f1938929a1f931762@users.noreply.github.com> Date: Thu, 9 Feb 2023 20:56:18 -0500 Subject: [PATCH] Fix and reorganize --- src/CourseOfferingsScraper.cpp | 2 +- src/GenerateHtml.cpp | 41 ++++++++++++++++++++++++++++------ src/common.h | 1 - 3 files changed, 35 insertions(+), 9 deletions(-) delete mode 100644 src/common.h diff --git a/src/CourseOfferingsScraper.cpp b/src/CourseOfferingsScraper.cpp index 7c25285..98fd536 100644 --- a/src/CourseOfferingsScraper.cpp +++ b/src/CourseOfferingsScraper.cpp @@ -5,7 +5,7 @@ #include #include #include -#include"common.h" +namespace fs = std::filesystem; struct term_data_t { Json::Value courses; diff --git a/src/GenerateHtml.cpp b/src/GenerateHtml.cpp index a649d12..97c9906 100644 --- a/src/GenerateHtml.cpp +++ b/src/GenerateHtml.cpp @@ -5,7 +5,7 @@ #include #include #include -#include"common.h" +namespace fs = std::filesystem; struct quatalog_data_t { Json::Value terms_offered; @@ -38,6 +38,8 @@ const std::unordered_map term_to_number { { TERM::FALL,"09" }, { TERM::WINTER,"12" } }; +std::unordered_set get_all_courses(const quatalog_data_t&); +std::string fix_course_ids(std::string); bool create_dir_if_not_exist(const fs::path&); const Json::Value& get_data(const Json::Value&,std::string); void generate_course_page(const std::string&,const quatalog_data_t&,std::ostream&); @@ -94,12 +96,35 @@ int main(const int argc, prerequisites_file >> quatalog_data.prerequisites; list_of_terms_file >> quatalog_data.list_of_terms; catalog_file >> quatalog_data.catalog; - for(const auto& course : quatalog_data.catalog.getMemberNames()) { - std::cerr << course << std::endl; - generate_course_page(course,quatalog_data,std::cout); + + auto courses = get_all_courses(quatalog_data); + for(const auto& course : courses) { + const auto& html_path = out_dir_path / (course + ".html"); + auto file = std::ofstream(html_path); + generate_course_page(course,quatalog_data,file); } } +std::unordered_set get_all_courses(const quatalog_data_t& qlog) { + std::unordered_set output; + for(const std::string& course : qlog.catalog.getMemberNames()) { + if(course.length() != 9) continue; + output.insert(fix_course_ids(course)); + } + for(const std::string& course : qlog.terms_offered.getMemberNames()) { + output.insert(fix_course_ids(course)); + } + return output; +} + +std::string fix_course_ids(std::string course) { + course[4] = '-'; + if(course.substr(0,3) == "STS") { + course[3] = 'O'; + } + return course; +} + bool create_dir_if_not_exist(const fs::path& path) { if(fs::exists(path)) { if(!fs::is_directory(path)) { @@ -134,6 +159,7 @@ const Json::Value& get_data(const Json::Value& data, void generate_course_page(const std::string& course_id, const quatalog_data_t& quatalog_data, std::ostream& os) { + std::cerr << "Generating course page for " << course_id << "..." << std::endl; std::string course_name, description; const auto& catalog_entry = quatalog_data.catalog[course_id]; const auto& prereqs_entry = get_data(quatalog_data.prerequisites,course_id); @@ -147,9 +173,10 @@ void generate_course_page(const std::string& course_id, description = catalog_entry["description"].asString(); } else { course_name = terms_offered[latest_term]["name"].asString(); - description = "This course is not in the most recent catalog." - "It may have been discontinued, or had its course " - "code changed."; + description = "This course is not in the most recent catalog. " + "It may have been discontinued, had its course " + "code changed, or just not be in the catalog for " + "some other reason."; } const auto& mid_digits = course_id.substr(6,2); if(mid_digits == "96" || mid_digits == "97") { diff --git a/src/common.h b/src/common.h deleted file mode 100644 index 42be13c..0000000 --- a/src/common.h +++ /dev/null @@ -1 +0,0 @@ -namespace fs = std::filesystem;