Add list of terms file to scraper

This commit is contained in:
3eef8a28f26fb2bcc514e6f1938929a1f931762 2023-02-07 09:42:37 -05:00
parent 2d5319902b
commit fe0a533795

View file

@ -10,6 +10,7 @@ namespace fs = std::filesystem;
struct quatalog_data_t { struct quatalog_data_t {
Json::Value terms_offered; Json::Value terms_offered;
Json::Value prerequisites; Json::Value prerequisites;
Json::Value list_of_terms;
}; };
struct term_data_t { struct term_data_t {
Json::Value courses; Json::Value courses;
@ -40,6 +41,7 @@ int main(const int argc,
<< " <data_directory>" << " <data_directory>"
<< " <terms_offered_file>" << " <terms_offered_file>"
<< " <prerequisites_file>" << " <prerequisites_file>"
<< " <list_of_terms_file>"
<< std::endl; << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -47,6 +49,7 @@ int main(const int argc,
const auto& data_dir_path = fs::path(argv[1]); const auto& data_dir_path = fs::path(argv[1]);
const auto& terms_offered_filename = std::string(argv[2]); const auto& terms_offered_filename = std::string(argv[2]);
const auto& prerequisites_filename = std::string(argv[3]); const auto& prerequisites_filename = std::string(argv[3]);
const auto& list_of_terms_filename = std::string(argv[4]);
if(!fs::is_directory(data_dir_path)) { if(!fs::is_directory(data_dir_path)) {
std::cerr << "Data directory argument " std::cerr << "Data directory argument "
@ -66,18 +69,21 @@ int main(const int argc,
quatalog_data_t data; quatalog_data_t data;
handle_term_dirs(term_dirs,data); handle_term_dirs(term_dirs,data);
std::fstream terms_offered_file{terms_offered_filename,std::ios::out};
std::fstream prerequisites_file{prerequisites_filename,std::ios::out};
Json::StreamWriterBuilder swb; Json::StreamWriterBuilder swb;
swb["indentation"] = " "; swb["indentation"] = " ";
std::unique_ptr<Json::StreamWriter> outWriter(swb.newStreamWriter()); std::unique_ptr<Json::StreamWriter> outWriter(swb.newStreamWriter());
std::fstream terms_offered_file{terms_offered_filename,std::ios::out};
std::fstream prerequisites_file{prerequisites_filename,std::ios::out};
std::fstream list_of_terms_file{list_of_terms_filename,std::ios::out};
outWriter->write(data.terms_offered,&terms_offered_file); outWriter->write(data.terms_offered,&terms_offered_file);
outWriter->write(data.prerequisites,&prerequisites_file); outWriter->write(data.prerequisites,&prerequisites_file);
outWriter->write(data.list_of_terms,&list_of_terms_file);
terms_offered_file.close(); terms_offered_file.close();
prerequisites_file.close(); prerequisites_file.close();
list_of_terms_file.close();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -102,7 +108,10 @@ void handle_term(const fs::directory_entry& term_entry,
std::fstream prereqs_file{prereqs_filename,std::ios::in}; std::fstream prereqs_file{prereqs_filename,std::ios::in};
std::cerr << "Processing term " << term << "..." << std::endl; std::cerr << "Processing term " << term << "..." << std::endl;
quatalog_data.terms_offered["all_terms"].append(term); quatalog_data.list_of_terms["all_terms"].append(term);
// TODO: Once change to QuACS that accounts for prerelease data
// is merged, change this
quatalog_data.list_of_terms["current_term"] = term;
term_data_t term_data; term_data_t term_data;
courses_file >> term_data.courses; courses_file >> term_data.courses;
@ -110,6 +119,9 @@ void handle_term(const fs::directory_entry& term_entry,
course_handler_t* course_handler; course_handler_t* course_handler;
if(term.substr(4,2) == "05") { if(term.substr(4,2) == "05") {
quatalog_data.list_of_terms["all_terms"].append(term+"02");
quatalog_data.list_of_terms["all_terms"].append(term+"03");
quatalog_data.list_of_terms["current_term"] = term+"03";
course_handler = handle_course_summer; course_handler = handle_course_summer;
} else { } else {
course_handler = handle_course; course_handler = handle_course;