diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index bc240a3..b3a52e0 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -25,4 +25,3 @@ jobs:
- name: Format code
run: |
make format
-
diff --git a/CopyToGitHub.ipynb b/CopyToGitHub.ipynb
new file mode 100644
index 0000000..c5f9b46
--- /dev/null
+++ b/CopyToGitHub.ipynb
@@ -0,0 +1,62 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 0,
+ "metadata": {
+ "colab": {
+ "provenance": [],
+ "authorship_tag": "ABX9TyPHJSVlBiqzKGsES92bvEWZ",
+ "include_colab_link": true
+ },
+ "kernelspec": {
+ "name": "python3",
+ "display_name": "Python 3"
+ },
+ "language_info": {
+ "name": "python"
+ }
+ },
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "view-in-github",
+ "colab_type": "text"
+ },
+ "source": [
+ "
"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "GbU-9zp544td",
+ "outputId": "f2219019-2f51-40e0-891b-49f270590a99"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "I was made in colab!\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(\"I was made in colab!\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [],
+ "metadata": {
+ "id": "4vATIZBg48_E"
+ },
+ "execution_count": null,
+ "outputs": []
+ }
+ ]
+}
\ No newline at end of file
diff --git a/fire-cli.py b/fire-cli.py
index f3668be..c6415c5 100644
--- a/fire-cli.py
+++ b/fire-cli.py
@@ -1,5 +1,6 @@
import fire
from mylib.bot import scrape
+
if __name__ == "__main__":
fire.Fire(scrape)
diff --git a/main.py b/main.py
index eb84ad4..caff3c2 100644
--- a/main.py
+++ b/main.py
@@ -15,7 +15,7 @@ class Wiki(BaseModel):
@app.post("/wiki")
async def scrape_story(wiki: Wiki):
- result = scrape(name=wiki.name)
+ result = scrape(name=wiki.name, length=1)
payload = {"wikipage": result}
json_compatible_item_data = jsonable_encoder(payload)
return JSONResponse(content=json_compatible_item_data)
diff --git a/mylib/bot.py b/mylib/bot.py
index da2ef43..bdf2f50 100644
--- a/mylib/bot.py
+++ b/mylib/bot.py
@@ -1,5 +1,5 @@
import wikipedia
-def scrape(name="Microsoft", length=1):
+def scrape(name, length):
result = wikipedia.summary(name, sentences=length)
return result
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index b4abfe0..f03b8c9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,4 +6,5 @@ ipython==8.1.1
fire==0.4.0
fastapi==0.75.0
pydantic==1.9.0
-uvicorn==0.17.6
\ No newline at end of file
+uvicorn==0.17.6
+click==8.0.2
\ No newline at end of file
diff --git a/statements.ipynb b/statements.ipynb
index ed87a09..288e26a 100644
--- a/statements.ipynb
+++ b/statements.ipynb
@@ -1,27 +1,10 @@
{
- "nbformat": 4,
- "nbformat_minor": 0,
- "metadata": {
- "colab": {
- "name": "statements",
- "provenance": [],
- "authorship_tag": "ABX9TyNe4+V/u39BRccCO1VGUuCj",
- "include_colab_link": true
- },
- "kernelspec": {
- "name": "python3",
- "display_name": "Python 3"
- },
- "language_info": {
- "name": "python"
- }
- },
"cells": [
{
"cell_type": "markdown",
"metadata": {
- "id": "view-in-github",
- "colab_type": "text"
+ "colab_type": "text",
+ "id": "view-in-github"
},
"source": [
"
"
@@ -29,16 +12,16 @@
},
{
"cell_type": "markdown",
- "source": [
- "## Learning Statements"
- ],
"metadata": {
"id": "l1ahQlB4K7-h"
- }
+ },
+ "source": [
+ "## Learning Statements"
+ ]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -48,8 +31,8 @@
},
"outputs": [
{
- "output_type": "stream",
"name": "stdout",
+ "output_type": "stream",
"text": [
"hello world\n"
]
@@ -61,51 +44,49 @@
},
{
"cell_type": "markdown",
- "source": [
- "### Variables"
- ],
"metadata": {
"id": "7Wc6DUjLLUFv"
- }
+ },
+ "source": [
+ "### Variables"
+ ]
},
{
"cell_type": "code",
- "source": [
- "variable = 1"
- ],
+ "execution_count": 2,
"metadata": {
"id": "cxJQjiczLGA-"
},
- "execution_count": null,
- "outputs": []
+ "outputs": [],
+ "source": [
+ "variable = 1"
+ ]
},
{
"cell_type": "code",
- "source": [
- "x = 1"
- ],
+ "execution_count": 3,
"metadata": {
"id": "xqu3CuI0Laia"
},
- "execution_count": 1,
- "outputs": []
+ "outputs": [],
+ "source": [
+ "x = 1"
+ ]
},
{
"cell_type": "code",
- "source": [
- "y = 2"
- ],
+ "execution_count": 4,
"metadata": {
"id": "3e-qtfRzL_0a"
},
- "execution_count": 2,
- "outputs": []
+ "outputs": [],
+ "source": [
+ "y = 2"
+ ]
},
{
"cell_type": "code",
- "source": [
- "x + y"
- ],
+ "execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -113,65 +94,63 @@
"id": "dWpUFe6HMBu5",
"outputId": "e19d8a70-812b-4690-e94b-cd31da9720a8"
},
- "execution_count": 3,
"outputs": [
{
- "output_type": "execute_result",
"data": {
"text/plain": [
"3"
]
},
+ "execution_count": 3,
"metadata": {},
- "execution_count": 3
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "x + y"
]
},
{
"cell_type": "code",
- "source": [
- ""
- ],
+ "execution_count": null,
"metadata": {
"id": "_Xbv6lnGMEPY"
},
- "execution_count": null,
- "outputs": []
+ "outputs": [],
+ "source": []
},
{
"cell_type": "markdown",
- "source": [
- "### Data Structures"
- ],
"metadata": {
"id": "gRPDPm50MQKa"
- }
+ },
+ "source": [
+ "### Data Structures"
+ ]
},
{
"cell_type": "markdown",
- "source": [
- "#### Lists"
- ],
"metadata": {
"id": "5HfnwC0lMk1Z"
- }
+ },
+ "source": [
+ "#### Lists"
+ ]
},
{
"cell_type": "code",
- "source": [
- "my_list = [1,2,3]"
- ],
+ "execution_count": 5,
"metadata": {
"id": "0YHo8VCBMSql"
},
- "execution_count": 4,
- "outputs": []
+ "outputs": [],
+ "source": [
+ "my_list = [1,2,3]"
+ ]
},
{
"cell_type": "code",
- "source": [
- "my_list[0]"
- ],
+ "execution_count": 6,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -179,25 +158,25 @@
"id": "YTwRFZTdMXk8",
"outputId": "3d126b2b-04c5-467f-e750-6e480f640563"
},
- "execution_count": 5,
"outputs": [
{
- "output_type": "execute_result",
"data": {
"text/plain": [
"1"
]
},
+ "execution_count": 6,
"metadata": {},
- "execution_count": 5
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "my_list[0]"
]
},
{
"cell_type": "code",
- "source": [
- "my_list[1]"
- ],
+ "execution_count": 6,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -205,25 +184,25 @@
"id": "gyi8180ZMZJD",
"outputId": "1a25a34c-3c71-4e5e-ebce-d88726c9f2eb"
},
- "execution_count": 6,
"outputs": [
{
- "output_type": "execute_result",
"data": {
"text/plain": [
"2"
]
},
+ "execution_count": 6,
"metadata": {},
- "execution_count": 6
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "my_list[1]"
]
},
{
"cell_type": "code",
- "source": [
- "my_list[2]"
- ],
+ "execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -231,25 +210,25 @@
"id": "9BltrokJMd2D",
"outputId": "15ba4e98-cf3d-48ed-e527-f82619aa3ff9"
},
- "execution_count": 7,
"outputs": [
{
- "output_type": "execute_result",
"data": {
"text/plain": [
"3"
]
},
+ "execution_count": 7,
"metadata": {},
- "execution_count": 7
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "my_list[2]"
]
},
{
"cell_type": "code",
- "source": [
- "type(my_list)"
- ],
+ "execution_count": 10,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -257,157 +236,152 @@
"id": "DqLAzK6TMhJH",
"outputId": "3b471454-f6ce-460d-ff70-77d5879a58ae"
},
- "execution_count": 10,
"outputs": [
{
- "output_type": "execute_result",
"data": {
"text/plain": [
"list"
]
},
+ "execution_count": 10,
"metadata": {},
- "execution_count": 10
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "type(my_list)"
]
},
{
"cell_type": "markdown",
- "source": [
- "#### Dictionary"
- ],
"metadata": {
"id": "qAwuIQg3Mw_6"
- }
+ },
+ "source": [
+ "#### Dictionary"
+ ]
},
{
"cell_type": "code",
- "source": [
- "my_dict = {1:\"one\", 2: \"two\"}"
- ],
+ "execution_count": 8,
"metadata": {
"id": "I4GkDdyuMynO"
},
- "execution_count": 8,
- "outputs": []
+ "outputs": [],
+ "source": [
+ "my_dict = {1:\"one\", 2: \"two\"}"
+ ]
},
{
"cell_type": "code",
- "source": [
- "type(my_dict)"
- ],
+ "execution_count": 9,
"metadata": {
- "id": "VoddwxWOM7eM",
- "outputId": "2df85560-8851-46a6-ef75-b7d180e3d523",
"colab": {
"base_uri": "https://localhost:8080/"
- }
+ },
+ "id": "VoddwxWOM7eM",
+ "outputId": "2df85560-8851-46a6-ef75-b7d180e3d523"
},
- "execution_count": 9,
"outputs": [
{
- "output_type": "execute_result",
"data": {
"text/plain": [
"dict"
]
},
+ "execution_count": 9,
"metadata": {},
- "execution_count": 9
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "type(my_dict)"
]
},
{
"cell_type": "code",
- "source": [
- "my_dict.keys()"
- ],
+ "execution_count": 11,
"metadata": {
- "id": "dKd4GW6FM_Xh",
- "outputId": "a6be43ef-008c-4cab-be2c-cc1d787a1812",
"colab": {
"base_uri": "https://localhost:8080/"
- }
+ },
+ "id": "dKd4GW6FM_Xh",
+ "outputId": "a6be43ef-008c-4cab-be2c-cc1d787a1812"
},
- "execution_count": 11,
"outputs": [
{
- "output_type": "execute_result",
"data": {
"text/plain": [
"dict_keys([1, 2])"
]
},
+ "execution_count": 11,
"metadata": {},
- "execution_count": 11
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "my_dict.keys()"
]
},
{
"cell_type": "code",
- "source": [
- "my_dict.values()"
- ],
+ "execution_count": 12,
"metadata": {
- "id": "nvXxjY59NGX_",
- "outputId": "0b3a1b5e-56b6-48e2-c388-89e341779bb3",
"colab": {
"base_uri": "https://localhost:8080/"
- }
+ },
+ "id": "nvXxjY59NGX_",
+ "outputId": "0b3a1b5e-56b6-48e2-c388-89e341779bb3"
},
- "execution_count": 12,
"outputs": [
{
- "output_type": "execute_result",
"data": {
"text/plain": [
"dict_values(['one', 'two'])"
]
},
+ "execution_count": 12,
"metadata": {},
- "execution_count": 12
+ "output_type": "execute_result"
}
+ ],
+ "source": [
+ "my_dict.values()"
]
},
{
"cell_type": "code",
- "source": [
- ""
- ],
+ "execution_count": null,
"metadata": {
"id": "SRdOvPg5NJnO"
},
- "execution_count": null,
- "outputs": []
+ "outputs": [],
+ "source": []
},
{
"cell_type": "markdown",
- "source": [
- "#### Loops"
- ],
"metadata": {
"id": "LnkEZZY4NP3p"
- }
+ },
+ "source": [
+ "#### Loops"
+ ]
},
{
"cell_type": "code",
- "source": [
- "for key,value in my_dict.items():\n",
- " print(f\"This is my key: {key}\")\n",
- " print(f\"This is my value: {value}\")"
- ],
+ "execution_count": 13,
"metadata": {
- "id": "ZeEI0C4nNRLs",
- "outputId": "ed0cac6f-f087-425a-8034-3dc69564b181",
"colab": {
"base_uri": "https://localhost:8080/"
- }
+ },
+ "id": "ZeEI0C4nNRLs",
+ "outputId": "ed0cac6f-f087-425a-8034-3dc69564b181"
},
- "execution_count": 13,
"outputs": [
{
- "output_type": "stream",
"name": "stdout",
+ "output_type": "stream",
"text": [
"This is my key: 1\n",
"This is my value: one\n",
@@ -415,44 +389,74 @@
"This is my value: two\n"
]
}
+ ],
+ "source": [
+ "for key,value in my_dict.items():\n",
+ " print(f\"This is my key: {key}\")\n",
+ " print(f\"This is my value: {value}\")"
]
},
{
"cell_type": "code",
- "source": [
- "for items in my_list:\n",
- " print(f\"This is the value in the list: {items}\")"
- ],
+ "execution_count": 14,
"metadata": {
- "id": "ZoMxJE_sNnkg",
- "outputId": "e44c2e9b-db52-495e-cd1b-8f7fcfdd8f56",
"colab": {
"base_uri": "https://localhost:8080/"
- }
+ },
+ "id": "ZoMxJE_sNnkg",
+ "outputId": "e44c2e9b-db52-495e-cd1b-8f7fcfdd8f56"
},
- "execution_count": 14,
"outputs": [
{
- "output_type": "stream",
"name": "stdout",
+ "output_type": "stream",
"text": [
"This is the value in the list: 1\n",
"This is the value in the list: 2\n",
"This is the value in the list: 3\n"
]
}
+ ],
+ "source": [
+ "for items in my_list:\n",
+ " print(f\"This is the value in the list: {items}\")"
]
},
{
"cell_type": "code",
- "source": [
- ""
- ],
+ "execution_count": null,
"metadata": {
"id": "Os7DxOI3NzZE"
},
- "execution_count": null,
- "outputs": []
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "colab": {
+ "authorship_tag": "ABX9TyNe4+V/u39BRccCO1VGUuCj",
+ "include_colab_link": true,
+ "name": "statements",
+ "provenance": []
+ },
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.10.8"
}
- ]
-}
\ No newline at end of file
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
diff --git a/test_wikibot.py b/test_wikibot.py
index b587dff..dfac3b5 100644
--- a/test_wikibot.py
+++ b/test_wikibot.py
@@ -4,11 +4,11 @@
def test_scrape():
- assert "Microsoft" in scrape("Microsoft")
+ assert "Microsoft" in scrape("Microsoft", 1)
def test_wikibot():
runner = CliRunner()
- result = runner.invoke(cli, ["--name", "Microsoft"])
+ result = runner.invoke(cli, ["--name", "Microsoft", "--length", "1"])
assert result.exit_code == 0
assert "Microsoft" in result.output
diff --git a/test_wikibot1.py b/test_wikibot1.py
new file mode 100644
index 0000000..284b08a
--- /dev/null
+++ b/test_wikibot1.py
@@ -0,0 +1,12 @@
+from mylib.bot import scrape
+from wikibot1 import cli
+from click.testing import CliRunner
+
+def test_scrape():
+ assert "Microsoft" in scrape("Microsoft",1)
+
+def test_wikibot():
+ runner = CliRunner()
+ result = runner.invoke(cli, ['--name', 'Microsoft', '--length', '1'])
+ assert result.exit_code == 0
+ assert 'Microsoft' in result.output
\ No newline at end of file
diff --git a/wikibot.py b/wikibot.py
index ae3526d..7994592 100644
--- a/wikibot.py
+++ b/wikibot.py
@@ -4,8 +4,9 @@
@click.command()
@click.option("--name", help="Web page we want to scrape")
-def cli(name):
- result = scrape(name)
+@click.option("--length", help="Web page we want to scrape")
+def cli(name, length):
+ result = scrape(name, length)
click.echo(click.style(f"{result}:", fg="blue"))
diff --git a/wikibot1.py b/wikibot1.py
new file mode 100644
index 0000000..5f3f5ab
--- /dev/null
+++ b/wikibot1.py
@@ -0,0 +1,16 @@
+import click
+from mylib.bot import scrape
+
+@click.command()
+@click.option('--name', help='Wikipedia word')
+@click.option('--length', help='number of sentences')
+def cli(name, length):
+ """
+ just scraping
+ """
+ result = scrape(name, length=length)
+ click.echo(click.style(f"{result}", fg="red"))
+ return result
+
+if __name__=='__main__':
+ cli()
\ No newline at end of file