-
Notifications
You must be signed in to change notification settings - Fork 51
Add load_json.py tool, remove --podcast flag from query.py #164
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
Changes from 1 commit
a86d8b6
d1c98ce
d80014f
8b25997
5fab841
4001250
dd79821
bfab170
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
| from typeagent.aitools import utils | ||
| from typeagent.knowpro.convsettings import ConversationSettings | ||
| from typeagent.podcasts import podcast | ||
| from typeagent.storage.sqlite.provider import SqliteStorageProvider | ||
| from typeagent.storage.utils import create_storage_provider | ||
|
|
||
|
|
||
|
|
@@ -69,8 +68,8 @@ async def load_json_to_database( | |
| conversation = await podcast.Podcast.read_from_file( | ||
| podcast_file_prefix, settings, dbname | ||
| ) | ||
| if isinstance(provider, SqliteStorageProvider): | ||
| provider.db.commit() | ||
| async with provider: | ||
| pass # Commit happens in __aexit__ | ||
|
|
||
| # Print statistics | ||
| if verbose: | ||
|
|
@@ -91,19 +90,6 @@ def main(): | |
| """Main entry point.""" | ||
| parser = argparse.ArgumentParser( | ||
| description="Load JSON-serialized podcast data into a SQLite database", | ||
| formatter_class=argparse.RawDescriptionHelpFormatter, | ||
| epilog=""" | ||
| Examples: | ||
| python tools/load_json.py tests/testdata/Episode_53_AdrianTchaikovsky_index -d podcast.db | ||
| python tools/load_json.py path/to/index -d output.db -v | ||
|
|
||
| Note: The index path should exclude the "_data.json" suffix. | ||
| """, | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "index_path", | ||
| help="Path to the podcast index files (excluding the '_data.json' suffix)", | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
|
|
@@ -120,9 +106,14 @@ def main(): | |
| help="Show verbose output including statistics", | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "index_path", | ||
| help="Path to the podcast index files (excluding the '_data.json' suffix)", | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| # Validate index file exists | ||
| # Ensure index file exists | ||
| index_file = args.index_path + "_data.json" | ||
| if not os.path.exists(index_file): | ||
| raise SystemExit( | ||
|
|
@@ -135,16 +126,13 @@ def main(): | |
| utils.load_dotenv() | ||
|
|
||
| # Run the loading process | ||
| try: | ||
| asyncio.run( | ||
| load_json_to_database( | ||
| args.index_path, | ||
| args.database, | ||
| args.verbose, | ||
| ) | ||
| asyncio.run( | ||
| load_json_to_database( | ||
| args.index_path, | ||
| args.database, | ||
| args.verbose, | ||
|
||
| ) | ||
| except (RuntimeError, ValueError) as err: | ||
| raise SystemExit(f"Error: {err}") | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, no, no! The
async withgoes around lines 68-70.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in bfab170 - moved
async with provider:to wrap the read_from_file call (lines 68-71).