-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/pdf processed by tika #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f9f52c2
various update + httpx
lpi-tn 7083def
Tika support for PDF
lpi-tn b063c36
rm httpx
lpi-tn 1845237
linter
lpi-tn 6d5c866
use new method
lpi-tn c093156
use new method
lpi-tn c655ccd
reliability
lpi-tn dc4bc18
test pdf processed by tika
lpi-tn 2e46bd9
test pdf processed by tika
lpi-tn d63db82
add tika address
lpi-tn d397e7c
remove useless lib
lpi-tn 6c1681d
remove useless lib
lpi-tn 1a58c99
remove useless lib
lpi-tn f9b08f3
typo
lpi-tn e046028
view
lpi-tn 45efd1b
rm french comments
lpi-tn f622ae1
typo
lpi-tn e67525c
delete
lpi-tn caa67d5
Update welearn_datastack/modules/pdf_extractor.py
lpi-tn 4abd80c
import re
lpi-tn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
welearn_datastack/nodes_workflow/DocumentPDFProcessor/document_pdf_processor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import csv | ||
| import logging | ||
| import os | ||
| from uuid import UUID | ||
|
|
||
| from sqlalchemy.orm import Session | ||
|
|
||
| from welearn_datastack.data.db_models import WeLearnDocument | ||
| from welearn_datastack.utils_.database_utils import create_db_session | ||
| from welearn_datastack.utils_.path_utils import setup_local_path | ||
|
|
||
| log_level: int = logging.getLevelName(os.getenv("LOG_LEVEL", "INFO")) | ||
| log_format: str = os.getenv( | ||
| "LOG_FORMAT", "[%(asctime)s][%(name)s][%(levelname)s] - %(message)s" | ||
| ) | ||
|
|
||
| if not isinstance(log_level, int): | ||
| raise ValueError("Log level is not recognized : '%s'", log_level) | ||
|
|
||
| logging.basicConfig( | ||
| level=logging.getLevelName(log_level), | ||
| format=log_format, | ||
| ) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| logger.info("DocumentPDFProcessor starting...") | ||
| input_artifact_id_url = os.getenv("ARTIFACT_ID_URL_CSV_NAME", "batch_ids.csv") | ||
| logger.info("Input artifact url csv name: %s", input_artifact_id_url) | ||
| local_artifcat_input, local_artifcat_output = setup_local_path() | ||
|
|
||
| # retrieve url data from files | ||
| logger.info("Retrieve URLs from file") | ||
|
|
||
| # Input IDs | ||
| with (local_artifcat_input / input_artifact_id_url).open( | ||
| "r" | ||
| ) as artifact_file_input: | ||
| spamreader = csv.reader(artifact_file_input, delimiter=",", quotechar='"') | ||
| ids_urls: list[UUID] = [UUID(row[0]) for row in spamreader] | ||
| logger.info("'%s' IDs URLs were retrieved", len(ids_urls)) | ||
|
|
||
| # Database management | ||
| logger.info("Create DB session") | ||
| db_session: Session = create_db_session() | ||
| logger.info("DB session created") | ||
|
|
||
| # Retrieve WeLearnDocument from database | ||
| logger.info("Retrieve WeLearnDocument from database") | ||
| welearn_documents: list = ( | ||
| db_session.query(WeLearnDocument).filter(WeLearnDocument.id.in_(ids_urls)).all() | ||
| ) | ||
| logger.info("'%s' WeLearnDocuments were retrieved", len(welearn_documents)) | ||
|
|
||
| if len(ids_urls) != len(welearn_documents): | ||
| logger.warning( | ||
| "'%s' IDs URLs were not found in the database", | ||
| len(ids_urls) - len(welearn_documents), | ||
| ) | ||
|
|
||
| if not welearn_documents: | ||
| logger.info("No WeLearnDocuments were retrieved") | ||
| return |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.