DEV Community

Cover image for That was quite an episode...
JaredHarbison
JaredHarbison

Posted on • Edited on

2

That was quite an episode...

Rails + React + Redux - Pt 5


This post is going to focus on creating an Appearance for each queen. I'll iterate through each Episode's contestants' ids to find_or_create_by the contestants' drag_names then create the Appearance using the Episode and Queen ids.


Let's get started!


1. Def get_seasons in season.rb to scrape the list of season names from Fandom, concatenate each season name into an array of URLS for each Season's Wikipedia page, then iterate through the array to .create!() an instance of each Season.

__see previous posts for the gist__

2. Def get_queens in queen.rb to scrape the list of queens' names from Fandom, concatenate each queen's name into an array of URLs for each Queen's Fandom page, then iterate through the array to .create!() an instance of each Queen and her attributes (including associations for Quotes and Trivia.

__see previous posts for the gist__

3. With Seasons and Queens instantiated, iterate through the Seasons and .create!() an appearance for each episode per Queen and her appropriate appearance attributes.

class Appearance < ApplicationRecord
belongs_to :queen
belongs_to :episode
def get_appearances
#### iterate through each season, pulling episode ids and contestants
Season.all.each do |season|
season.episodes.each do |episode|
episode_id = episode.id
#### the stored array of contestants needs a little work before we create Appearances
contestants = episode.contestants.split(", ").map do |contestant|
contestant.gsub(/[^0-9a-z%&!\n\/(). ]/i, '').strip
end
#### iterate through the array of contestants to create an Appearance for each Episode
contestants.map do |contestant|
Appearance.create(
episode_id: episode_id,
#### use the contestants list as it appeared on the season's Fandom page to find the corresponding Queens
queen_id: Queen.find_or_create_by(drag_name: contestant).id
)
end
end
end
end
end
view raw appearance.rb hosted with ❤ by GitHub

A subsequent post will include the last in the scraping segment of the project, where I'll gather the queens stats from each episode and store them with her appearance! Then I'll have enough data to start creating the user interface.


That's all folks!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more