kweather-cord


Namekweather-cord JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryNice Embed Template for Korean Weather for Discord Bot
upload_time2024-09-17 06:55:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024-present Gooraeng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords koreaweather kweather 공공데이터포털 기상청 discord discord.py
VCS
bugtrack_url
requirements discord.py rapidfuzz
Travis-CI No Travis.
coveralls test coverage No coveralls.
            kweathercord
===============

.. image:: https://img.shields.io/pypi/v/kweather-cord.svg
    :target: https://pypi.org/project/kweather-cord/
    :alt: PyPI version info
.. image:: https://img.shields.io/pypi/pyversions/kweather-cord.svg
    :target: https://pypi.org/project/kweather-cord/
    :alt: PyPI supported Python versions
    
- kweathercord은 대한민국 기상청 API을 이용하여 대한민국의 날씨를 Embed, Button, Select Menu를 이용하여 확인하는 간단한 도구입니다.
- 초단기실황, 초단기예보, 단기예보를 지원합니다.
- NOAA 알고리즘을 통해 조회하시는 지역의 일출, 일몰 시간에 맞추어 아이콘이 조정됩니다.
- 코드 한 줄만으로 모든 게 알아서 이루어집니다.
- Discord.py 관련 오류 이외의 오류는 알아서 핸들링합니다.


구현 모습
---------------
.. image:: example/results/weather1.png
    :width: 400


파이썬 요구 사항
------------------
- Python 3.8 이상에서 작동합니다.


의존 패키지
----------------
- Discord.py (2.4.0 이상)
- RapidFuzz


설치 방법
--------------

- 설치 시

.. code:: sh

    pip install -U kweather-cord

- 업그레이드 시

.. code:: sh

    pip install kweather-cord --upgrade


제한 사항
-------------
- 당일 최저/최고 온도는 명시적으로 제공하지 않으나 초단기예보 및 단기예보에서 각각 06시와 15시를 최저/최고온도로 지정하고 있습니다. 초단기실황은 지원하지 않습니다.
- 이 패키지는 discord.py의 app_commands 모듈(Slash command)의 사용을 권장합니다.
- 또, 안정적인 동작을 위해, defer가 적용되어 있습니다. Error Handling 시, edit_original_response나 followup.send 메소드 사용을 고려해주십시오.


사용 예시
-------------

1. bot.py
~~~~~~~~~~~~

.. code:: py

    from aiohttp import ClientSession
    from discord.ext import commands
    from kweathercord import KoreaForecastForDiscord

    import discord
    import os

    initial_extensions = (
        'cogs.weather',
    )


    class Test(commands.Bot):
        def __init__(self):
            intents = discord.Intents.default()
            super().__init__(
                command_prefix=None,
                intents=intents
            )
        
        async def setup_hook(self) -> None:
            # aiohttp 사용을 위한 선언 (라이브러리 한계로 인해 동기 함수에서 선언할 수 없습니다.)
            # Kweathercord는 clientsession을 선언하지 않아도, 라이브러리에서 핸들링 할 수 있습니다.
            self.session = ClientSession()
            self.weather = KoreaForecastForDiscord(self, self.session)
            # 기상청 API 키를 넣어주세요.
            # self.weather.api_key = '여기에 기상청 api키를 넣거나, .env로부터 api 키를 얻어내세요.'

            for extension in initial_extensions:
                try:
                    await self.load_extension(extension)
                except Exception:
                    raise
            # await self.tree.sync()
        
        async def on_ready(self):
            ...
            # on_ready에서 사용해도 되나, 이 함수에서 복잡한 작업은 권장되지 않습니다.
            # 따라서, setup_hook 함수 내에서 이루어지는 것이 좋습니다.



2. cog.weather
~~~~~~~~~~~~~~~~

.. code:: py

    from discord import app_commands, Interaction
    from discord.ext import commands
    from typing import Literal

    from bot_example import Test   


    class Weather(commands.Cog):
        def __init__(self, bot : Test) -> None:
            self.bot = bot
            
        # commands.Context는 가급적 사용하지 않습니다.
        @app_commands.command(name='날씨', description='지역의 날씨를 찾아보세요')
        @app_commands.describe(
            where='어느 지역의 날씨를 검색하실 건가요?',
            period='어떤 검색 방식을 이용하실 건가요?'
        )
        @app_commands.rename(where='지역', period='기간')
        async def search(self, interaction : Interaction, where : str, period : Literal['지금', '향후 6시간', '향후 3~4일']):
            try:
                if period == '지금':
                    method = '초단기실황'
                elif period == '향후 3~4일':
                    method = '단기예보'
                else:
                    method = '초단기예보'
                await self.bot.weather.get_weather(interaction, method=method, city=where, hidden=True)

            except Exception as e:
                # interaction.response.defer를 사용하기 때문에,
                # 오류 발생 시, Interaction.Followup 이나 InteractionMessage만 허용됩니다.
                await interaction.followup.send(e)
        
        # use_area_list가 true이면 autocomplete 사용 시 지역 리스트를 불러올 수 있습니다.
        @search.autocomplete('where')
        async def search_ac(self, interaction : Interaction, current : str):
            result = [
                app_commands.Choice(name=choice, value=choice)
                for choice in self.bot.weather.area_list
                if current.replace(' ', '') in choice.replace(' ', '')
            ]
            # 디스코드 한계로 인해 선택 옵션은 최대 25개까지 입니다.
            return result[:25]


    async def setup(bot : Test):
        await bot.add_cog(Weather(bot))


참고 링크
-----------

- `대한민국 기상청 API <https://www.data.go.kr/tcs/dss/selectApiDataDetailView.do?publicDataPk=15084084>`_

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "kweather-cord",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "koreaweather, kweather, \uacf5\uacf5\ub370\uc774\ud130\ud3ec\ud138, \uae30\uc0c1\uccad, discord, discord.py",
    "author": null,
    "author_email": "Gooraeng <birdyoon1998@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c9/8c/b8072aec1d3ea1bbadbb90c40b113998cfa2e3a32e97de5bfb661300d126/kweather_cord-0.1.3.tar.gz",
    "platform": null,
    "description": "kweathercord\r\n===============\r\n\r\n.. image:: https://img.shields.io/pypi/v/kweather-cord.svg\r\n    :target: https://pypi.org/project/kweather-cord/\r\n    :alt: PyPI version info\r\n.. image:: https://img.shields.io/pypi/pyversions/kweather-cord.svg\r\n    :target: https://pypi.org/project/kweather-cord/\r\n    :alt: PyPI supported Python versions\r\n    \r\n- kweathercord\uc740 \ub300\ud55c\ubbfc\uad6d \uae30\uc0c1\uccad API\uc744 \uc774\uc6a9\ud558\uc5ec \ub300\ud55c\ubbfc\uad6d\uc758 \ub0a0\uc528\ub97c Embed, Button, Select Menu\ub97c \uc774\uc6a9\ud558\uc5ec \ud655\uc778\ud558\ub294 \uac04\ub2e8\ud55c \ub3c4\uad6c\uc785\ub2c8\ub2e4.\r\n- \ucd08\ub2e8\uae30\uc2e4\ud669, \ucd08\ub2e8\uae30\uc608\ubcf4, \ub2e8\uae30\uc608\ubcf4\ub97c \uc9c0\uc6d0\ud569\ub2c8\ub2e4.\r\n- NOAA \uc54c\uace0\ub9ac\uc998\uc744 \ud1b5\ud574 \uc870\ud68c\ud558\uc2dc\ub294 \uc9c0\uc5ed\uc758 \uc77c\ucd9c, \uc77c\ubab0 \uc2dc\uac04\uc5d0 \ub9de\ucd94\uc5b4 \uc544\uc774\ucf58\uc774 \uc870\uc815\ub429\ub2c8\ub2e4.\r\n- \ucf54\ub4dc \ud55c \uc904\ub9cc\uc73c\ub85c \ubaa8\ub4e0 \uac8c \uc54c\uc544\uc11c \uc774\ub8e8\uc5b4\uc9d1\ub2c8\ub2e4.\r\n- Discord.py \uad00\ub828 \uc624\ub958 \uc774\uc678\uc758 \uc624\ub958\ub294 \uc54c\uc544\uc11c \ud578\ub4e4\ub9c1\ud569\ub2c8\ub2e4.\r\n\r\n\r\n\uad6c\ud604 \ubaa8\uc2b5\r\n---------------\r\n.. image:: example/results/weather1.png\r\n    :width: 400\r\n\r\n\r\n\ud30c\uc774\uc36c \uc694\uad6c \uc0ac\ud56d\r\n------------------\r\n- Python 3.8 \uc774\uc0c1\uc5d0\uc11c \uc791\ub3d9\ud569\ub2c8\ub2e4.\r\n\r\n\r\n\uc758\uc874 \ud328\ud0a4\uc9c0\r\n----------------\r\n- Discord.py (2.4.0 \uc774\uc0c1)\r\n- RapidFuzz\r\n\r\n\r\n\uc124\uce58 \ubc29\ubc95\r\n--------------\r\n\r\n- \uc124\uce58 \uc2dc\r\n\r\n.. code:: sh\r\n\r\n    pip install -U kweather-cord\r\n\r\n- \uc5c5\uadf8\ub808\uc774\ub4dc \uc2dc\r\n\r\n.. code:: sh\r\n\r\n    pip install kweather-cord --upgrade\r\n\r\n\r\n\uc81c\ud55c \uc0ac\ud56d\r\n-------------\r\n- \ub2f9\uc77c \ucd5c\uc800/\ucd5c\uace0 \uc628\ub3c4\ub294 \uba85\uc2dc\uc801\uc73c\ub85c \uc81c\uacf5\ud558\uc9c0 \uc54a\uc73c\ub098 \ucd08\ub2e8\uae30\uc608\ubcf4 \ubc0f \ub2e8\uae30\uc608\ubcf4\uc5d0\uc11c \uac01\uac01 06\uc2dc\uc640 15\uc2dc\ub97c \ucd5c\uc800/\ucd5c\uace0\uc628\ub3c4\ub85c \uc9c0\uc815\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4. \ucd08\ub2e8\uae30\uc2e4\ud669\uc740 \uc9c0\uc6d0\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.\r\n- \uc774 \ud328\ud0a4\uc9c0\ub294 discord.py\uc758 app_commands \ubaa8\ub4c8(Slash command)\uc758 \uc0ac\uc6a9\uc744 \uad8c\uc7a5\ud569\ub2c8\ub2e4.\r\n- \ub610, \uc548\uc815\uc801\uc778 \ub3d9\uc791\uc744 \uc704\ud574, defer\uac00 \uc801\uc6a9\ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4. Error Handling \uc2dc, edit_original_response\ub098 followup.send \uba54\uc18c\ub4dc \uc0ac\uc6a9\uc744 \uace0\ub824\ud574\uc8fc\uc2ed\uc2dc\uc624.\r\n\r\n\r\n\uc0ac\uc6a9 \uc608\uc2dc\r\n-------------\r\n\r\n1. bot.py\r\n~~~~~~~~~~~~\r\n\r\n.. code:: py\r\n\r\n    from aiohttp import ClientSession\r\n    from discord.ext import commands\r\n    from kweathercord import KoreaForecastForDiscord\r\n\r\n    import discord\r\n    import os\r\n\r\n    initial_extensions = (\r\n        'cogs.weather',\r\n    )\r\n\r\n\r\n    class Test(commands.Bot):\r\n        def __init__(self):\r\n            intents = discord.Intents.default()\r\n            super().__init__(\r\n                command_prefix=None,\r\n                intents=intents\r\n            )\r\n        \r\n        async def setup_hook(self) -> None:\r\n            # aiohttp \uc0ac\uc6a9\uc744 \uc704\ud55c \uc120\uc5b8 (\ub77c\uc774\ube0c\ub7ec\ub9ac \ud55c\uacc4\ub85c \uc778\ud574 \ub3d9\uae30 \ud568\uc218\uc5d0\uc11c \uc120\uc5b8\ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4.)\r\n            # Kweathercord\ub294 clientsession\uc744 \uc120\uc5b8\ud558\uc9c0 \uc54a\uc544\ub3c4, \ub77c\uc774\ube0c\ub7ec\ub9ac\uc5d0\uc11c \ud578\ub4e4\ub9c1 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\r\n            self.session = ClientSession()\r\n            self.weather = KoreaForecastForDiscord(self, self.session)\r\n            # \uae30\uc0c1\uccad API \ud0a4\ub97c \ub123\uc5b4\uc8fc\uc138\uc694.\r\n            # self.weather.api_key = '\uc5ec\uae30\uc5d0 \uae30\uc0c1\uccad api\ud0a4\ub97c \ub123\uac70\ub098, .env\ub85c\ubd80\ud130 api \ud0a4\ub97c \uc5bb\uc5b4\ub0b4\uc138\uc694.'\r\n\r\n            for extension in initial_extensions:\r\n                try:\r\n                    await self.load_extension(extension)\r\n                except Exception:\r\n                    raise\r\n            # await self.tree.sync()\r\n        \r\n        async def on_ready(self):\r\n            ...\r\n            # on_ready\uc5d0\uc11c \uc0ac\uc6a9\ud574\ub3c4 \ub418\ub098, \uc774 \ud568\uc218\uc5d0\uc11c \ubcf5\uc7a1\ud55c \uc791\uc5c5\uc740 \uad8c\uc7a5\ub418\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.\r\n            # \ub530\ub77c\uc11c, setup_hook \ud568\uc218 \ub0b4\uc5d0\uc11c \uc774\ub8e8\uc5b4\uc9c0\ub294 \uac83\uc774 \uc88b\uc2b5\ub2c8\ub2e4.\r\n\r\n\r\n\r\n2. cog.weather\r\n~~~~~~~~~~~~~~~~\r\n\r\n.. code:: py\r\n\r\n    from discord import app_commands, Interaction\r\n    from discord.ext import commands\r\n    from typing import Literal\r\n\r\n    from bot_example import Test   \r\n\r\n\r\n    class Weather(commands.Cog):\r\n        def __init__(self, bot : Test) -> None:\r\n            self.bot = bot\r\n            \r\n        # commands.Context\ub294 \uac00\uae09\uc801 \uc0ac\uc6a9\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.\r\n        @app_commands.command(name='\ub0a0\uc528', description='\uc9c0\uc5ed\uc758 \ub0a0\uc528\ub97c \ucc3e\uc544\ubcf4\uc138\uc694')\r\n        @app_commands.describe(\r\n            where='\uc5b4\ub290 \uc9c0\uc5ed\uc758 \ub0a0\uc528\ub97c \uac80\uc0c9\ud558\uc2e4 \uac74\uac00\uc694?',\r\n            period='\uc5b4\ub5a4 \uac80\uc0c9 \ubc29\uc2dd\uc744 \uc774\uc6a9\ud558\uc2e4 \uac74\uac00\uc694?'\r\n        )\r\n        @app_commands.rename(where='\uc9c0\uc5ed', period='\uae30\uac04')\r\n        async def search(self, interaction : Interaction, where : str, period : Literal['\uc9c0\uae08', '\ud5a5\ud6c4 6\uc2dc\uac04', '\ud5a5\ud6c4 3~4\uc77c']):\r\n            try:\r\n                if period == '\uc9c0\uae08':\r\n                    method = '\ucd08\ub2e8\uae30\uc2e4\ud669'\r\n                elif period == '\ud5a5\ud6c4 3~4\uc77c':\r\n                    method = '\ub2e8\uae30\uc608\ubcf4'\r\n                else:\r\n                    method = '\ucd08\ub2e8\uae30\uc608\ubcf4'\r\n                await self.bot.weather.get_weather(interaction, method=method, city=where, hidden=True)\r\n\r\n            except Exception as e:\r\n                # interaction.response.defer\ub97c \uc0ac\uc6a9\ud558\uae30 \ub54c\ubb38\uc5d0,\r\n                # \uc624\ub958 \ubc1c\uc0dd \uc2dc, Interaction.Followup \uc774\ub098 InteractionMessage\ub9cc \ud5c8\uc6a9\ub429\ub2c8\ub2e4.\r\n                await interaction.followup.send(e)\r\n        \r\n        # use_area_list\uac00 true\uc774\uba74 autocomplete \uc0ac\uc6a9 \uc2dc \uc9c0\uc5ed \ub9ac\uc2a4\ud2b8\ub97c \ubd88\ub7ec\uc62c \uc218 \uc788\uc2b5\ub2c8\ub2e4.\r\n        @search.autocomplete('where')\r\n        async def search_ac(self, interaction : Interaction, current : str):\r\n            result = [\r\n                app_commands.Choice(name=choice, value=choice)\r\n                for choice in self.bot.weather.area_list\r\n                if current.replace(' ', '') in choice.replace(' ', '')\r\n            ]\r\n            # \ub514\uc2a4\ucf54\ub4dc \ud55c\uacc4\ub85c \uc778\ud574 \uc120\ud0dd \uc635\uc158\uc740 \ucd5c\ub300 25\uac1c\uae4c\uc9c0 \uc785\ub2c8\ub2e4.\r\n            return result[:25]\r\n\r\n\r\n    async def setup(bot : Test):\r\n        await bot.add_cog(Weather(bot))\r\n\r\n\r\n\ucc38\uace0 \ub9c1\ud06c\r\n-----------\r\n\r\n- `\ub300\ud55c\ubbfc\uad6d \uae30\uc0c1\uccad API <https://www.data.go.kr/tcs/dss/selectApiDataDetailView.do?publicDataPk=15084084>`_\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024-present Gooraeng  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Nice Embed Template for Korean Weather for Discord Bot",
    "version": "0.1.3",
    "project_urls": {
        "Repository": "https://github.com/Gooraeng/KweatherDiscord"
    },
    "split_keywords": [
        "koreaweather",
        " kweather",
        " \uacf5\uacf5\ub370\uc774\ud130\ud3ec\ud138",
        " \uae30\uc0c1\uccad",
        " discord",
        " discord.py"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a7fb550e51e92202df40efe5581e650f66bb5bafc90a0474d872a206ce47551",
                "md5": "bb70aee2f8ec40b938404262a4f93dd1",
                "sha256": "da43e634d6b6a2211ec20bd5a05b83edda27401a310964c66967fb777ec7ea34"
            },
            "downloads": -1,
            "filename": "kweather_cord-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bb70aee2f8ec40b938404262a4f93dd1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 241698,
            "upload_time": "2024-09-17T06:55:02",
            "upload_time_iso_8601": "2024-09-17T06:55:02.227102Z",
            "url": "https://files.pythonhosted.org/packages/3a/7f/b550e51e92202df40efe5581e650f66bb5bafc90a0474d872a206ce47551/kweather_cord-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c98cb8072aec1d3ea1bbadbb90c40b113998cfa2e3a32e97de5bfb661300d126",
                "md5": "84f6c1c6e7fa4bc83d52511ded6285d9",
                "sha256": "adcb0e2dd4b76f416ba77f2885706297cf47d41fca8940fb521d2756899cafb3"
            },
            "downloads": -1,
            "filename": "kweather_cord-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "84f6c1c6e7fa4bc83d52511ded6285d9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 236206,
            "upload_time": "2024-09-17T06:55:05",
            "upload_time_iso_8601": "2024-09-17T06:55:05.055835Z",
            "url": "https://files.pythonhosted.org/packages/c9/8c/b8072aec1d3ea1bbadbb90c40b113998cfa2e3a32e97de5bfb661300d126/kweather_cord-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-17 06:55:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Gooraeng",
    "github_project": "KweatherDiscord",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "discord.py",
            "specs": [
                [
                    ">=",
                    "2.4.0"
                ]
            ]
        },
        {
            "name": "rapidfuzz",
            "specs": [
                [
                    ">=",
                    "3.9"
                ]
            ]
        }
    ],
    "lcname": "kweather-cord"
}
        
Elapsed time: 0.34996s