vidhiya-saagar / spg2

🌕 Suraj Prakash Granth - Rails 7 Admin Application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Import Footnote Entries from Contentful to Local Database

dsomel21 opened this issue · comments

Description

We need to import footnote entries from Contentful into our local database. This should be made available through a method ContentfulImporter.new.import_latest_entries.

Tasks

  1. Establish a connection with Contentful.
  2. Fetch TukFootnote and PauriFootnote entries.
  3. Parse the entries and map them to the corresponding book, chapter, and tuk/pauri in the local database.
  4. Save the entry_uuid from Contentful for each entry in the local database.

Detailed Steps:

1. Establish Connection with Contentful

Use the Contentful Ruby SDK to establish a connection with Contentful. Ensure to handle the case when the required ENV variables are not available.

def initialize
  @client = Contentful::Client.new(
    :access_token => ENV.fetch('CMS_ACCESS_TOKEN', nil),
    :space => ENV.fetch('CMS_SPACE_ID', nil),
    :dynamic_entries => :auto,
    :raise_errors => true
  )
end

2. Fetch Entries from Contentful

Fetch TukFootnote and PauriFootnote entries from Contentful.

This is pretty much what the data looks like:

Screen Shot 2023-05-27 at 9 19 35 AM Screen Shot 2023-05-27 at 9 32 31 AM

3. Parse Entries and Map to Local Data

The entries have a specific format indicating the book ID, chapter number, and verse/stanza or pauri number. This needs to be parsed and mapped to the corresponding book, chapter, and tuk/pauri in the local database.

The format for TukFootnote is Book 1 Chapter 1 Tuk 48.4, and for PauriFootnote is Book 16 Chapter 2 Pauri 4.

4. Save entry_uuid in Local Database

For each entry, save the entry_uuid from Contentful in the local database. This entry_uuid is required to display the correct entry.

Expected Outcome

At the end of this process, we should have all the latest TukFootnote and PauriFootnote entries imported into our local database with the entry_uuid saved for each entry.

Additional Information

  • Use the Contentful Ruby SDK for fetching entries from Contentful.
  • Ensure to handle exceptions and errors appropriately, especially when required ENV variables are not available or when the entry format is not as expected.