|
|
|
|
@ -3,9 +3,7 @@ import os
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
import logging
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
ruby_recent_login_url = os.getenv("RUBY_RECENT_LOGIN_URL", "http://test-data.educoder.net/api/home/online_users.json")
|
|
|
|
|
ruby_oline_size_url = os.getenv("RUBY_ONLINE_SIZE_URL", "http://test-data.educoder.net/api/home/online_num")
|
|
|
|
|
|
|
|
|
|
@ -19,17 +17,13 @@ def get_recent_login_info(page_index=1, page_size=10):
|
|
|
|
|
data = {"status":-1,"message":"响应失败"}
|
|
|
|
|
try:
|
|
|
|
|
url = f"{ruby_recent_login_url}?limit={page_size}&page={page_index}"
|
|
|
|
|
response = requests.get(url, timeout=5)
|
|
|
|
|
response = requests.get(url)
|
|
|
|
|
data = response.json()
|
|
|
|
|
response.raise_for_status() # 如果响应状态码不是 200,会引发 HTTPError
|
|
|
|
|
logging.debug(f"请求{url} 返回参数: {data}")
|
|
|
|
|
except ValueError:
|
|
|
|
|
logging.info(f"请求{url} 返回参数: {data}")
|
|
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
|
|
# 处理可能的请求错误
|
|
|
|
|
logging.error("online_size解析错误")
|
|
|
|
|
except requests.exceptions.HTTPError:
|
|
|
|
|
logging.error(f"online_size: {ruby_recent_login_url}请求发生错误")
|
|
|
|
|
except requests.exceptions.ConnectTimeout:
|
|
|
|
|
logging.error(f"online_size: {ruby_recent_login_url}请求超时")
|
|
|
|
|
logging.info(f"recent_login_info请求发生错误: {e}")
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
@ -42,18 +36,13 @@ def get_online_size():
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
url = ruby_oline_size_url
|
|
|
|
|
response = requests.get(url, timeout=5)
|
|
|
|
|
response = requests.get(url)
|
|
|
|
|
response.raise_for_status() # 如果响应状态码不是 200,会引发 HTTPError
|
|
|
|
|
data = response.json()
|
|
|
|
|
logging.debug(f"请求{url} 返回参数: {data}")
|
|
|
|
|
logging.info(f"请求{url} 返回参数: {data}")
|
|
|
|
|
return data.get('data', {}).get('online_num', 0)
|
|
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
|
|
# 处理可能的请求错误
|
|
|
|
|
logging.error("online_size解析错误")
|
|
|
|
|
except requests.exceptions.HTTPError:
|
|
|
|
|
logging.error(f"online_size: {ruby_oline_size_url}请求发生错误")
|
|
|
|
|
except requests.exceptions.ConnectTimeout:
|
|
|
|
|
logging.error(f"online_size: {ruby_oline_size_url}请求超时")
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
logging.info(f"online_size请求发生错误: {e}")
|
|
|
|
|
return 0
|