commit f6b04c2d7bc324d7d4c1b38caaca790f1a7fac97 Author: GoldBro233 Date: Wed Aug 27 11:51:05 2025 +0800 Init: Add fetch radar map on Nanjing diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..2a1b856 --- /dev/null +++ b/.env.dev @@ -0,0 +1 @@ +LOG_LEVEL=DEBUG diff --git a/.env.prod b/.env.prod new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..093255f --- /dev/null +++ b/.gitignore @@ -0,0 +1,141 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# End of https://www.toptal.com/developers/gitignore/api/python \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b1d2f0 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# radar-bot + +## How to start + +1. generate project using `nb create` . +2. create your plugin using `nb plugin create` . +3. writing your plugins under `src/plugins` folder. +4. run your bot using `nb run --reload` . + +## Documentation + +See [Docs](https://nonebot.dev/) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1ccf671 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[project] +name = "radar-bot" +version = "0.1.0" +description = "radar-bot" +readme = "README.md" +requires-python = ">=3.9, <4.0" + +[tool.nonebot] +adapters = [ + { name = "OneBot V12", module_name = "nonebot.adapters.onebot.v12" } +] +plugins = [] +plugin_dirs = ["src/plugins"] +builtin_plugins = ["echo"] diff --git a/src/plugins/rdnj.py b/src/plugins/rdnj.py new file mode 100644 index 0000000..b14117c --- /dev/null +++ b/src/plugins/rdnj.py @@ -0,0 +1,53 @@ +from nonebot.params import EventMessage +from nonebot.plugin import on_command +from nonebot.rule import to_me + +from nonebot.adapters.onebot.v11 import Bot,MessageEvent, GroupMessageEvent +from nonebot.adapters.onebot.v11.message import Message, MessageSegment + +import datetime, requests, time, pytz + +rdnj = on_command("rdnj", rule=to_me()) + +@rdnj.handle() +async def _( + bot: Bot, + evt: GroupMessageEvent, + evt_msg: EventMessage() +): + + tz_utc = pytz.timezone('Etc/GMT') + now_utc = datetime.datetime.now(tz_utc) + aligned_min = (now_utc.minute // 6) * 6 + utc_time = now_utc.replace( + minute=aligned_min, + second=0, + microsecond=0 + ) + + url = ( + f"https://image.nmc.cn/product/" + f"{utc_time:%Y}/{utc_time:%m}/{utc_time:%d}/RDCP/" + f"SEVP_AOC_RDCP_SLDAS3_ECREF_AZ9250_L88_PI_" + f"{utc_time:%Y%m%d%H%M}00000.PNG" + ) + + while True: + try: + reponse = requests.get(url,allow_redirects=True) + if reponse.status_code==200: + break + else: + utc_time -= datetime.timedelta(minutes=6) + url = ( + f"https://image.nmc.cn/product/" + f"{utc_time:%Y}/{utc_time:%m}/{utc_time:%d}/RDCP/" + f"SEVP_AOC_RDCP_SLDAS3_ECREF_AZ9250_L88_PI_" + f"{utc_time:%Y%m%d%H%M}00000.PNG" + ) + + except requests.exceptions.RequestException as e: + print(f"Error Fetching Image: {e}") + + msg = MessageSegment(f"{url}\n") + MessageSegment.image(reponse.content) + await rdnj.finish(msg)