Skip to content

Commit

Permalink
Adds in OBS TN rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
richmahn committed May 15, 2024
1 parent 0fdd1e5 commit c5d4b0d
Show file tree
Hide file tree
Showing 9 changed files with 1,204 additions and 443 deletions.
9 changes: 6 additions & 3 deletions hit_preview_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

root = 'https://preview.door43.org'
# Open the webpage
driver.get(root + "?owner=unfoldingWord&owner=Door43-Catalog&subject=Aligned+Bible&subject=Bible&subject=Greek+New+Testament&subject=Hebrew+Old+Testament&subject=Open+Bible+Stories&subject=Translation+Words&subject=TSV+Translation+Notes&subject=TSV+Translation+Questions&stage=latest&sort=released&order=desc")
# driver.get(root + "?subject=Aligned+Bible&subject=Bible&subject=Open+Bible+Stories&subject=Translation+Words&subject=TSV+Translation+Notes&subject=TSV+Translation+Questions&stage=latest&sort=released&order=desc")
#driver.get(root + "?owner=unfoldingWord&owner=Door43-Catalog&subject=Aligned+Bible&subject=Bible&subject=Greek+New+Testament&subject=Hebrew+Old+Testament&subject=Open+Bible+Stories&subject=Translation+Words&subject=TSV+Translation+Notes&subject=TSV+Translation+Questions&stage=latest&sort=released&order=desc")
driver.get(root + "?subject=Aligned+Bible&subject=Bible&subject=Open+Bible+Stories&subject=Translation+Words&subject=TSV+Translation+Notes&subject=TSV+Translation+Questions&stage=latest&sort=released&order=desc")
#driver.get(root + "?owner=unfoldingWord&owner=Door43-Catalog&subject=TSV%20Translation%20Notes&stage=latest&sort=released&order=desc")

# Wait for the component to load
wait = WebDriverWait(driver, 60) # adjust the timeout as needed
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'css-1kv5bp7'))) # replace with the actual class name of your component
# wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'css-c0czuf'))) # replace with the actual class name of your component
time.sleep(10)

# time.sleep(3)

Expand All @@ -55,6 +56,8 @@
# Find all the URLs on the page
urls = list(set([a['href'] for a in soup.find_all('a', href=True)]))

print(urls);

# Loop through the URLs
for url in urls:
if not url.startswith('/u/'):
Expand Down
83 changes: 83 additions & 0 deletions hit_preview_pages_with_catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from bs4 import BeautifulSoup
import time
import requests



completed_urls = []
try:
with open('./completed_urls', 'r') as file:
completed_urls = file.read().splitlines()
except FileNotFoundError:
pass

# Setup Chrome options
chrome_options = webdriver.ChromeOptions()

# Set the location of the webdriver
webdriver_service = Service(ChromeDriverManager().install())

# Initialize the driver

# url = "http://git.door43.org/api/v1/catalog/search?owner=unfoldingWord&owner=Door43-Catalog&subject=TSV+Translation+Notes&stage=latest&limit=1"
url = "http://git.door43.org/api/v1/catalog/search?owner=unfoldingWord&owner=Door43-Catalog&subject=Aligned+Bible&subject=Bible&subject=Greek+New+Testament&subject=Hebrew+Old+Testament&subject=Open+Bible+Stories&subject=Translation+Words&subject=TSV+Translation+Notes&subject=TSV+Translation+Questions&stage=latest&sort=released&order=desc&limit=1"

response = requests.get(url)
entries = response.json()['data']

driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)
wait = WebDriverWait(driver, 60) # adjust the timeout as needed

root = "https://preview.door43.org"
temp_url = "about:blank"

# Loop through the entries
for entry in entries:
for ingredient in entry['ingredients']:
url = "/u/unfoldingWord/en_tn/v71#psa"
# url = f"/u/{entry['full_name']}/{entry['branch_or_tag_name']}?rerender=1#{ingredient['identifier']}"
# if url in completed_urls:
# continue

print(root+url)

try:
driver.get(temp_url)

# Open the page
driver.get(root+url)

# Wait for the component to load
# wait.until(EC.presence_of_element_located((By.XPATH, "//div[contains(text(), 'Error')] | //div[@id='web-preview'][child::*]")))

# Wait for the button to not be disabled or for the div with text "Error" to appear
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[value=print]")) or EC.presence_of_element_located((By.XPATH, "//div[contains(text(), 'Error')]")))

print("SUCCESS: "+url)
# Add a delay to ensure the page has fully loaded (adjust as needed)
# time.sleep(5)
# Read the completed URLs from the file if it exists

# Add the completed URL to the array
completed_urls.append(url)

# Save the completed URLs to the file
with open('./completed_urls', 'w') as file:
file.write('\n'.join(completed_urls))

time.sleep(2)
except Exception as e:
print("ERROR: "+url)
print(e)
continue
break
break

# Close the WebDriver
driver.quit()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "door43-preview-app",
"private": true,
"version": "1.0.7",
"version": "1.0.8",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
12 changes: 8 additions & 4 deletions src/components/App.context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import RcTranslationAcademy from '@components/RcTranslationAcademy';
import RcTranslationNotes from '@components/RcTranslationNotes';
import RcTranslationQuestions from '@components/RcTranslationQuestions';
import RcTranslationWords from '@components/RcTranslationWords';
// import RcObsTranslationNotes from '@libs/rcObsTranslationNotes/components/RcObsTranslationNotes' // Uncomment this if you need to use RcObsTranslationNotes
import RcObsTranslationNotes from '@components/RcObsTranslationNotes';
import RcObsTranslationQuestions from '@components/RcObsTranslationQuestions';
import TsBible from '@components/TsBible';

export const AppContext = React.createContext();
Expand Down Expand Up @@ -372,9 +373,12 @@ export function AppContextProvider({ children }) {
case 'Translation Words':
setResourceComponent(() => RcTranslationWords);
return;
// case 'TSV OBS Translation Notes':
// setResourceComponent(() => RcObsTranslationNotes)
// return;
case 'TSV OBS Translation Notes':
setResourceComponent(() => RcObsTranslationNotes)
return;
case 'TSV OBS Translation Questions':
setResourceComponent(() => RcObsTranslationQuestions)
return;
default:
setErrorMessage(`Conversion of \`${catalogEntry.subject}\` resources is currently not supported.`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Bible.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default function Bible() {
setErrorMessage(`Book \`${bookId}\` is not in repo's project list.`);
}

getRepoContentsContent(catalogEntry.repo.url, filePath, catalogEntry.commit_sha, authToken)
getRepoContentsContent(catalogEntry.repo.url, filePath, catalogEntry.commit_sha, authToken, false)
.then((_usfmText) => {
const usfmJSON = usfm.toJSON(_usfmText);
for (let i = 0; i < usfmJSON?.headers?.length; ++i) {
Expand Down
21 changes: 15 additions & 6 deletions src/components/OpenBibleStories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { createTheme, ThemeProvider } from '@mui/material';
import { AppContext } from '@components/App.context';

// Custom hooks imports
import useGetOBSData from '../hooks/useGetOBSData';
import useGenerateOpenBibleStoriesHtml from '../hooks/useGenerateOpenBibleStoriesHtml';
import useGetOBSData from '@hooks/useGetOBSData';
import useGenerateOpenBibleStoriesHtml from '@hooks/useGenerateOpenBibleStoriesHtml';
import useFetchZipFileData from '@hooks/useFetchZipFileData';

// Other imports
Expand Down Expand Up @@ -60,7 +60,7 @@ const theme = createTheme({
export default function OpenBibleStories() {
const {
state: { catalogEntry, urlInfo, navAnchor, authToken },
actions: { setStatusMessage, setErrorMessage, setHtmlSections, setNavAnchor, setBuiltWith },
actions: { setStatusMessage, setErrorMessage, setHtmlSections, setNavAnchor, setBuiltWith, setSupportedBooks, setBookId, setCanChangeColumns },
} = useContext(AppContext);

const [imageResolution, setImageResolution] = useState('360px');
Expand All @@ -84,15 +84,25 @@ export default function OpenBibleStories() {
const obsHtmlSections = useGenerateOpenBibleStoriesHtml({ obsData, setErrorMessage, resolution: imageResolution });

useEffect(() => {
if (!catalogEntry) {
setErrorMessage('No catalog entry for this resource found.');
return;
}
setStatusMessage(
<>
Preparing OBS Preview.
Preparing preview for {catalogEntry.title}.
<br />
Please wait...
</>
);
bibleReferenceActions.applyBooksFilter(['obs']);
}, [setStatusMessage]);
setSupportedBooks('obs');
setBookId('obs');
setHtmlSections((prevState) => {
return { ...prevState, css: { web: webCss, print: printCss } };
});
setCanChangeColumns(false);
}, [catalogEntry, setCanChangeColumns, setErrorMessage, setBookId, setHtmlSections, setStatusMessage, setSupportedBooks]);

useEffect(() => {
if (catalogEntry) {
Expand All @@ -115,7 +125,6 @@ export default function OpenBibleStories() {
setHtmlSections((prevState) => {
return { ...prevState, ...obsHtmlSections };
});
setHtmlSections((prevState) => {return {...prevState, css: {web: webCss, print: printCss}}});
setStatusMessage('');
}
}, [obsHtmlSections, setHtmlSections, setStatusMessage]);
Expand Down
Loading

0 comments on commit c5d4b0d

Please sign in to comment.