Skip to content

Commit

Permalink
feat: scrape teacher sigarra url
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspalma committed Sep 6, 2024
1 parent f55a788 commit 85c2a2c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
16 changes: 13 additions & 3 deletions src/scrapper/database/dbs/create_db_sqlite3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,27 @@ CREATE TABLE `slot_class` (
PRIMARY KEY (`slot_id`, `class_id`)
);

CREATE TABLE `professor_link` (
`id` INTEGER PRIMARY KEY,
`link` varchar(256)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `class_professor`
-- Table structure for table `schedule_professor`
--

CREATE TABLE `slot_professor` (
`slot_id` INTEGER NOT NULL,
`professor_id` INTEGER NOT NULL,
`professor_link_id` INTEGER NOT NULL,
FOREIGN KEY (`slot_id`) REFERENCES `slot` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`professor_id`) REFERENCES `professor` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`professor_link_id`) REFERENCES `professor_link` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`slot_id`, `professor_id`)
);
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;


-- --------------------------------------------------------
--
Expand All @@ -133,7 +142,8 @@ CREATE TABLE `slot_professor` (
CREATE TABLE `professor` (
`id` INTEGER PRIMARY KEY,
`professor_acronym` varchar(16),
`professor_name` varchar(100)
`professor_name` varchar(100),
`professor_url` varchar(128)
);

-- --------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/scrapper/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ class SlotClass(scrapy.Item):
class SlotProfessor(scrapy.Item):
slot_id = scrapy.Field()
professor_id = scrapy.Field()
professor_link_id = scrapy.Field()

class ProfessorLink(scrapy.Item):
id = scrapy.Field()
link = scrapy.Field()

class Professor(scrapy.Item):
id = scrapy.Field()
professor_acronym = scrapy.Field()
professor_name = scrapy.Field()
professor_url = scrapy.Field()
13 changes: 10 additions & 3 deletions src/scrapper/spiders/slot_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from scrapper.settings import CONFIG, PASSWORD, USERNAME

from ..database.Database import Database
from ..items import Slot, Class, SlotProfessor, Professor, SlotClass
from ..items import Slot, Class, SlotProfessor, Professor, SlotClass, ProfessorLink


def get_class_id(course_unit_id, class_name):
Expand Down Expand Up @@ -180,7 +180,8 @@ def extractSchedule(self, response):
yield Professor(
id=sigarra_id,
professor_acronym=teacher["acronym"],
professor_name=name
professor_name=name,
professor_url=teacher["sigarra_url"]
)

for current_class in schedule["classes"]:
Expand All @@ -206,9 +207,15 @@ def extractSchedule(self, response):
(sigarra_id, name) = self.get_professor_info(
teacher)

yield ProfessorLink(
id=schedule["id"],
professor_link=teacher["sigarra_url"]
)

yield SlotProfessor(
slot_id=schedule["id"],
professor_id=sigarra_id
professor_id=sigarra_id,
professor_link=schedule["id"]
)

for current_class in schedule["classes"]:
Expand Down
10 changes: 9 additions & 1 deletion src/scripts/dump/schema/create_db_sqlite3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ CREATE TABLE `slot_class` (
PRIMARY KEY (`slot_id`, `class_id`)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

CREATE TABLE `professor_link` (
`id` INTEGER PRIMARY KEY,
`link` varchar(256)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

-- --------------------------------------------------------

--
Expand All @@ -128,8 +133,10 @@ CREATE TABLE `slot_class` (
CREATE TABLE `slot_professor` (
`slot_id` INTEGER NOT NULL,
`professor_id` INTEGER NOT NULL,
`professor_link_id` INTEGER NOT NULL,
FOREIGN KEY (`slot_id`) REFERENCES `slot` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`professor_id`) REFERENCES `professor` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`professor_link_id`) REFERENCES `professor_link` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`slot_id`, `professor_id`)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

Expand All @@ -142,7 +149,8 @@ CREATE TABLE `slot_professor` (
CREATE TABLE `professor` (
`id` INTEGER PRIMARY KEY,
`professor_acronym` varchar(16),
`professor_name` varchar(100)
`professor_name` varchar(100),
`professor_url` varchar(128)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

-- --------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion src/scripts/dump/schema/schema_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ CREATE TABLE `slot_class` (
CREATE TABLE `professor` (
`id` INTEGER PRIMARY KEY,
`professor_acronym` varchar(16),
`professor_name` varchar(100)
`professor_name` varchar(100),
`professor_url` varchar(128)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

CREATE TABLE `professor_link` (
`id` INTEGER PRIMARY KEY,
`link` varchar(256)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

-- --------------------------------------------------------
Expand All @@ -144,8 +150,10 @@ CREATE TABLE `professor` (
CREATE TABLE `slot_professor` (
`slot_id` INTEGER NOT NULL,
`professor_id` INTEGER NOT NULL,
`professor_link_id` INTEGER NOT NULL,
FOREIGN KEY (`slot_id`) REFERENCES `slot` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`professor_id`) REFERENCES `professor` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`professor_link_id`) REFERENCES `professor_link` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`slot_id`, `professor_id`)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

Expand Down

0 comments on commit 85c2a2c

Please sign in to comment.