Преглед изворни кода

增加天气预报 task 模块

jack пре 2 месеци
комит
42e35cc089
3 измењених фајлова са 280 додато и 0 уклоњено
  1. 65 0
      .gitignore
  2. 112 0
      message/weather/get_one_week_weather.py
  3. 103 0
      requirements.txt

+ 65 - 0
.gitignore

@@ -0,0 +1,65 @@
+.DS_Store
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+.idea/*
+xml_files/
+
+# 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/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+other/split_clash_config/split_config
+ai_news/save_data
+daily/*.txt

+ 112 - 0
message/weather/get_one_week_weather.py

@@ -0,0 +1,112 @@
+# -*- coding: utf-8 -*-
+'''
+获取天气预报
+'''
+import os
+import sys
+import time
+from datetime import datetime
+from bs4 import BeautifulSoup
+import httpx
+
+sys.path.append(os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo'))
+SUB_PROJECT_NAME = "获取天气预报"
+PROJECT_PATH = os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo')
+
+class Weather():
+    def main(self):
+        print('开始获取天气预报数据')
+        try:
+            area_code = '59287'
+            one_week = [
+                '/tomorrow-%s.htm' % area_code,
+                '/third-%s.htm' % area_code,
+                '/fourth-%s.htm' % area_code,
+                '/fifth-%s.htm' % area_code,
+                '/sixth-%s.htm' % area_code,
+                '/seventh-%s.htm' % area_code,
+            ]
+            url = "https://tianqi.2345.com/today-%s.htm" % area_code
+            header = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8'}
+            response = httpx.get(url=url, headers=header)
+            response.encoding = "utf-8"
+            bs = BeautifulSoup(response.text, 'html.parser')
+
+            one_week_weather = []
+            for week in one_week:
+                a = bs.find_all('a', href=week)
+                a = ' '.join(a[0].text.split())
+                one_week_weather.append(a)
+
+        except Exception as e:
+            print(e)
+            print('Weather forecast')
+            exit(0)
+
+        text = "天气预报: {}获取并发送\n".format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())) + '\n'.join(
+            one_week_weather)
+
+        # 推送到 message
+        GotifyNotifier('天气预报数', text, 'weather').send_message()
+
+        print('天气预报数据已获取')
+
+
+class GotifyNotifier:
+    def __init__(self, title, message, token_name=''):
+        self.gotify_url = 'https://gotify.erhe.top'
+        self.app_token = self.match_token_name(token_name)
+        self.title = title
+        self.message = message
+
+    def match_token_name(self, name):
+        token_name_dict = {
+            'base': 'A8EVb0Cmxnb2vfk',
+            'coin': 'AgfOJESqDKftBTQ',
+            'dlt': 'A3bqt9Dlbs.fPUb',
+            'AirdropTasksNews': 'Aoe0VKt-kkZnm8d',
+            'weather': 'A9KF--mx_12PjSu',
+            'news': 'AT2QGp_vyCX4akW',
+            'CheckAndRemind': 'Aw7XKE2Ppk7Dgwk',
+            'test': 'A0Xg6ZE5946iBYg',
+        }
+
+        token = token_name_dict.get(name)
+        if token:
+            return token
+        else:
+            return token_name_dict['base']
+
+    def send_message(self):
+        # 构建POST请求的headers
+        headers = {
+            'Content-Type': 'application/json'
+        }
+
+        # 构建POST请求的body
+        body = {
+            'title': self.title,
+            'message': self.message
+        }
+
+        # 发送POST请求
+        with httpx.Client() as client:
+            response = client.post(
+                url=f"{self.gotify_url}/message?token={self.app_token}",
+                headers=headers,
+                json=body
+            )
+
+        # 或者可以使用 curl
+        # curl -k "https://gotify.erhe.top/message?token=A0Xg6ZE5946iBYg" -F "title=测试发送信息" -F "message=假装有信息,测试发送" -F "priority=5"
+
+        # 检查响应状态码
+        if response.status_code == 200:
+            print('Gotify Message sent successfully!')
+        else:
+            print('Failed to send message:', response.text)
+
+if __name__ == "__main__":
+    # W = Weather().main()
+    print(PROJECT_PATH)
+

+ 103 - 0
requirements.txt

@@ -0,0 +1,103 @@
+aiofiles==24.1.0
+aiohappyeyeballs==2.4.0
+aiohttp==3.10.5
+aiohttp-socks==0.8.4
+aiosignal==1.3.1
+annotated-types==0.6.0
+anyio==4.1.0
+appdirs==1.4.4
+APScheduler==3.10.4
+async-timeout==4.0.3
+attrs==23.1.0
+beautifulsoup4==4.12.2
+blinker==1.7.0
+Brotli==1.1.0
+bs4==0.0.1
+certifi==2023.11.17
+cffi==1.16.0
+charset-normalizer==3.3.2
+click==8.1.7
+colorama==0.4.6
+cryptography==41.0.7
+distro==1.9.0
+dnspython==2.4.2
+exceptiongroup==1.2.0
+fastapi==0.108.0
+frozenlist==1.4.0
+greenlet==3.0.3
+h11==0.14.0
+h2==4.1.0
+helium==5.0.3
+hpack==4.0.0
+httpcore==1.0.2
+httpx==0.25.2
+hyperframe==6.0.1
+idna==3.6
+importlib-metadata==7.0.0
+jieba==0.42.1
+jiter==0.5.0
+jsonschema==4.23.0
+jsonschema-specifications==2023.12.1
+kaitaistruct==0.10
+lxml==5.3.0
+matrix-client==0.4.0
+matrix-nio==0.25.0
+multidict==6.0.4
+numpy==1.26.4
+openai==1.42.0
+outcome==1.3.0.post0
+packaging==24.1
+paho-mqtt==2.1.0
+pillow==11.0.0
+ping3==4.0.4
+playwright==1.46.0
+psycopg2-binary==2.9.10
+pyasn1==0.5.1
+pycparser==2.21
+pycryptodome==3.19.0
+pydantic==2.5.3
+pydantic_core==2.14.6
+pydivert==2.1.0
+pyee==11.1.0
+PyExecJS==1.5.1
+pygpt4all==1.1.0
+pygptj==2.0.3
+pymongo==4.6.1
+pyOpenSSL==23.3.0
+pyparsing==3.1.1
+pyppeteer==2.0.0
+PyRSS2Gen==1.1
+pyshark==0.6
+PySocks==1.7.1
+python-socks==2.5.1
+pytz==2024.1
+PyYAML==6.0.2
+redis==5.0.1
+referencing==0.35.1
+requests==2.31.0
+rpds-py==0.20.0
+rsa==4.9
+scapy==2.5.0
+schedule==1.2.1
+selenium==4.16.0
+selenium-wire==5.1.0
+six==1.16.0
+sniffio==1.3.0
+sortedcontainers==2.4.0
+soupsieve==2.5
+starlette==0.32.0.post1
+termcolor==2.4.0
+tqdm==4.66.1
+trio==0.23.1
+trio-websocket==0.11.1
+typing_extensions==4.12.2
+tzlocal==5.2
+unpaddedbase64==2.1.0
+urllib3==1.26.18
+uvicorn==0.25.0
+websockets==10.4
+wsproto==1.2.0
+xmltodict==0.13.0
+yarl==1.9.4
+zipp==3.17.0
+zstandard==0.22.0