jack 11 месяцев назад
Родитель
Сommit
118c6ec6bc
5 измененных файлов с 89 добавлено и 16 удалено
  1. 18 0
      demo/demo_httpx_async.py
  2. 14 0
      demo/demo_httpx_sync.py
  3. 9 0
      demo/demo_playwright.py
  4. 30 0
      demo/demo_send_gotify.py
  5. 18 16
      message/message_coin_detail.py

+ 18 - 0
demo/demo_httpx_async.py

@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+import httpx
+import asyncio
+
+
+async def async_get_example():
+    async with httpx.AsyncClient() as client:
+        response = await client.get('https://httpbin.org/get')
+        print(f"Status Code: {response.status_code}")
+        print(f"Response Content: {response.text}")
+
+
+async def main():
+    await async_get_example()
+
+
+if __name__ == "__main__":
+    asyncio.run(main())

+ 14 - 0
demo/demo_httpx_sync.py

@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+import httpx
+
+
+def sync_get_example():
+    # 使用 httpx 发送 GET 请求
+    response = httpx.get('https://httpbin.org/get')
+    # 打印状态码和响应内容
+    print(f"Status Code: {response.status_code}")
+    print(f"Response Content: {response.text}")
+
+
+if __name__ == "__main__":
+    sync_get_example()

+ 9 - 0
demo/demo_playwright.py

@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+from playwright.sync_api import sync_playwright
+
+with sync_playwright() as playwright:
+    browser = playwright.chromium.launch(headless=False)
+    page = browser.new_page()
+    page.goto('https://example.com')
+    page.screenshot(path='example.png')
+    browser.close()

+ 30 - 0
demo/demo_send_gotify.py

@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+import httpx
+
+# Gotify服务器地址
+gotify_url = "https://gotify.erhe.top/message?token=A9KF--mx_12PjSu"
+
+# 要发送的消息内容
+message = {
+    "message": "测试消息",
+    "title": "测试标题",
+    "priority": 5
+}
+
+
+async def send_message():
+    async with httpx.AsyncClient() as client:
+        try:
+            response = await client.post(gotify_url, json=message)
+            if response.status_code == 200:
+                print("消息发送成功")
+            else:
+                print(f"消息发送失败,状态码: {response.status_code}")
+        except httpx.RequestException as e:
+            print(f"请求出现异常: {e}")
+
+
+if __name__ == "__main__":
+    import asyncio
+
+    asyncio.run(send_message())

+ 18 - 16
message/message_coin_detail.py

@@ -40,7 +40,7 @@ def fetch_coin_data(target):
             target_data = eval(data['result'][0]['data'])
             target_data = target_data[0]
 
-            print(target_data)
+            # print(target_data)
 
             # 获取数据值
             name = target_data['name']
@@ -53,16 +53,18 @@ def fetch_coin_data(target):
             logoUrl = target_data['logoUrl']
 
             # 拼接到 text 中
-            text += f'Name: {name}\n'
-            text += f'Ranking: {rank}\n'
-            text += f'Price: {price}\n'
-            text += f'24H Transaction Volume: {volume}\n'
-            text += f'24H Price Change: {change}\n'
-            text += f'Market Capitalization: {market_cap}\n'
-            text += f'Diluted Market Value: {dilute}\n'
-            text += f'Logo: {logoUrl}\n'
+            text = '{}  {}  {}  {}  {}  {}'.format(name, price, change, volume, rank, market_cap)
+            print(text)
+            # text += f'Name: {name}\n'
+            # text += f'Ranking: {rank}\n'
+            # text += f'Price: {price}\n'
+            # text += f'24H Transaction Volume: {volume}\n'
+            # text += f'24H Price Change: {change}\n'
+            # text += f'Market Capitalization: {market_cap}\n'
+            # text += f'Diluted Market Value: {dilute}\n'
+            # text += f'Logo: {logoUrl}\n'
 
-            return text
+            return text + '\n'
 
 
 def fetch_vix_data():
@@ -152,7 +154,7 @@ def main():
     text = ''
 
     # 获取币币实时价格
-    target_list = ['btc', 'eth', 'sol', 'grass', 'sui', 'doge', 'arb', 'ath', 'move', 'pepe']
+    target_list = ['btc', 'eth', 'sol', 'grass', 'sui', 'doge', 'arb', 'ath', 'move', 'pepe', 'degen']
     for target in target_list:
         for retry in range(1, retry_count + 1):
             result = fetch_coin_data(target)
@@ -182,14 +184,14 @@ def main():
             text += result + '\n\n'
             break
         else:
-            print(f"Failed to fetch Gas data. retry: {retry}")
+            # print(f"Failed to fetch Gas data. retry: {retry}")
             if retry == retry_count:
                 text += f"Failed to fetch Gas data. retry count: {retry}"
 
-    if text:
-        GotifyNotifier('Real-time coin price\n', text, 'AgfOJESqDKftBTQ').send_message()
-    else:
-        print('No Data')
+    # if text:
+    #     GotifyNotifier('Real-time coin price\n', text, 'AgfOJESqDKftBTQ').send_message()
+    # else:
+    #     print('No Data')
 
 
 if __name__ == "__main__":