Skip to content

Commit 34774b3

Browse files
committed
doc: updates usecases.ipynb with async GitHub parser.
1 parent 875eafb commit 34774b3

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

docs/notebooks/usecases.ipynb

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@
585585
{
586586
"data": {
587587
"text/plain": [
588-
"[BranchInfo(name='github_url_arg', last_commit=Commit(sha='59ade5b5268686e0360978000502ff3c63b39623', date='2025-12-05T17:34:35Z')),\n",
588+
"[BranchInfo(name='github_url_arg', last_commit=Commit(sha='875eafb3fb6de757b22a121dcd56ab0c2ffda676', date='2025-12-05T18:36:16Z')),\n",
589589
" BranchInfo(name='main', last_commit=Commit(sha='6c84dcbfa0f637bf8b30a9ab37062fe36737985a', date='2025-11-30T09:46:33Z'))]"
590590
]
591591
},
@@ -772,6 +772,60 @@
772772
"\n",
773773
"pprint(pulls)"
774774
]
775+
},
776+
{
777+
"cell_type": "markdown",
778+
"id": "1f7e1df9",
779+
"metadata": {},
780+
"source": [
781+
"### Использование асинхронного GitHub парсера"
782+
]
783+
},
784+
{
785+
"cell_type": "code",
786+
"execution_count": 24,
787+
"id": "d8de0bfc",
788+
"metadata": {},
789+
"outputs": [
790+
{
791+
"name": "stdout",
792+
"output_type": "stream",
793+
"text": [
794+
"'https://github.com/OSLL/code-plagiarism/blob/main/LICENSE'\n",
795+
"'https://github.com/OSLL/code-plagiarism/tree/main/rc/webparsers/__init__.py'\n",
796+
"'https://github.com/OSLL/code-plagiarism/tree/main/rc/webparsers/async_github_parser.py'\n",
797+
"'https://github.com/OSLL/code-plagiarism/tree/main/rc/webparsers/github_parser.py'\n",
798+
"'https://github.com/OSLL/code-plagiarism/tree/main/rc/webparsers/types.py'\n"
799+
]
800+
}
801+
],
802+
"source": [
803+
"import asyncio\n",
804+
"import aiohttp\n",
805+
"\n",
806+
"from webparsers.async_github_parser import AsyncGithubParser\n",
807+
"\n",
808+
"\n",
809+
"async def handle_link(gh_parser: AsyncGithubParser, link: str):\n",
810+
" async for work_info in gh_parser.get_files_generator_from_url(link):\n",
811+
" pprint(work_info.link)\n",
812+
"\n",
813+
"\n",
814+
"async def main():\n",
815+
" timeout = aiohttp.ClientTimeout(total=5)\n",
816+
" async with aiohttp.ClientSession(timeout=timeout) as session:\n",
817+
" gh_parser = AsyncGithubParser(session, token=env_config.get(\"ACCESS_TOKEN\"))\n",
818+
" tasks = []\n",
819+
" for link in [\n",
820+
" \"https://github.com/OSLL/code-plagiarism/tree/main/src/webparsers\",\n",
821+
" \"https://github.com/OSLL/code-plagiarism/blob/main/LICENSE\"\n",
822+
" ]:\n",
823+
" tasks.append(handle_link(gh_parser, link))\n",
824+
" await asyncio.gather(*tasks)\n",
825+
"\n",
826+
"\n",
827+
"await main()"
828+
]
775829
}
776830
],
777831
"metadata": {

src/webparsers/async_github_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AsyncGithubParser:
3232
>>> import asyncio
3333
>>> import aiohttp
3434
>>> async def requests():
35-
... timeout = ClientTimeout(total=5)
35+
... timeout = aiohttp.ClientTimeout(total=5)
3636
... async with aiohttp.ClientSession(timeout=timeout) as session:
3737
... gh_parser = AsyncGithubParser(session, token=<token>)
3838
... tasks = []

0 commit comments

Comments
 (0)