How queens-qmulus/qu-scrapers works
Project Type and Purpose
• The project is a specialized scraping library and command-line tool designed to harvest data from a variety of web resources at Queen’s University.
• From the README, it is clear that the goal is to provide multiple independent scraper modules (buildings, courses, news, textbooks) that can be invoked individually or collectively via the “run_scraper.py” module.
• It’s integrated with CI/CD (visualized by GitHub Actions) and follows a modular design to aid maintainability and extensibility.
File Structure
• Top-level files (e.g., Pipfile, README.md, run_scraper.py, tests.py) indicate standard Python project setup with environment management and testing.
• The “quartzscrapers” package contains an __init__.py and a logging configuration file (logging.yaml), plus a logs folder to persist logs.
• The “scrapers” subpackage is organized into domain-specific directories (buildings, courses, news, textbooks, and a test_scraper) where each directory contains its own __init__.py, main logic file, helper file, and in some cases its own README.
• The “scrapers/utils” folder hosts shared utilities (e.g., config and a generic scraper method) that likely play a central role across the different scrapers.
Key Components to Capture
a. Application Entry Points:
• Run Command: “run_scraper.py” serves as the command-line entry point to trigger multiple scraping tasks.
• Library Use: Application code can also import the “quartzscrapers” package to directly trigger individual scrapers (via classes like Textbooks, Buildings, etc.).
b. Core Scraper Modules:
• Separate modules for each scraping domain:
• Buildings Scraper (in quartzscrapers/scrapers/buildings)
• Courses Scraper (in quartzscrapers/scrapers/courses)
• News Scraper (in quartzscrapers/scrapers/news)
• Textbooks Scraper (in quartzscrapers/scrapers/textbooks)
• Each module may have both a main scraping class/function and helper functions.
c. Shared Utilities and Configuration:
• “quartzscrapers/scrapers/utils”: Centralized configuration logic and a generic scraper routine that provides a common interface or shared functionality across scrapers.
• Environment configuration: Usage of .env (populated via environment variables like GITHUB_TOKEN, GOOGLE_MAPS_KEY, etc.) for external API keys and credentials.
d. Logging:
• Centralized logging configuration given in “quartzscrapers/logging.yaml”, with actual log outputs directed to the “quartzscrapers/logs” folder.
e. Testing & CI/CD:
• “tests.py” for the testing suite.
• GitHub workflows under .github/workflows indicating automated test and build processes.
Relationships and Interactions
• The “run_scraper.py” module interacts with the individual scraper modules by invoking their scrape() functions, optionally passing configuration arguments (like location paths).
• The scrapers themselves use the shared utility functions (from “scrapers/utils”) to apply common configuration settings, environment variable handling, and other preprocessing tasks.
• All components use logging as a cross-cutting feature for monitoring, thus a logging component is linked to every scrapper component.
Architectural Patterns & Design Principles
• Modularity: Each scraper is a self-contained module with its own README and helper functions, making it easy to extend or modify in isolation.
• Separation of Concerns: There is a clear separation between configuration (utils/config.py), logging (logging.yaml), scraper logic (within each scraper folder), and orchestration (run_scraper.py).
• Reusability: The utility module encourages code reuse for common scraping tasks across the different projects.
• Command Design: The existence of a CLI entry point (run_scraper.py) indicates a command design pattern where different commands (scraper invocations) can be executed.