update
This commit is contained in:
15
main.py
15
main.py
@@ -4,11 +4,10 @@ from datetime import datetime
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# 配置常量
|
# 配置常量
|
||||||
GIT_INTERVAL = 3600 # Git提交间隔(秒)
|
GIT_INTERVAL = 180 # Git提交间隔(秒)
|
||||||
FETCH_INTERVAL = 3600 # 数据获取间隔(秒)
|
FETCH_INTERVAL = 60 # 数据获取间隔(秒)
|
||||||
LOG_FILE = "btc_plus.log"
|
LOG_FILE = "btc_plus.log"
|
||||||
|
|
||||||
|
|
||||||
@@ -185,6 +184,7 @@ def fetch_btc_plus_stats(stage_no=1):
|
|||||||
|
|
||||||
def save_to_csv(data, filename="btc_plus_rewards.csv"):
|
def save_to_csv(data, filename="btc_plus_rewards.csv"):
|
||||||
"""将数据保存到CSV文件"""
|
"""将数据保存到CSV文件"""
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
timestamp = data.get("timestamp", get_current_time())
|
timestamp = data.get("timestamp", get_current_time())
|
||||||
|
|
||||||
if "btcPlusRewardByAddress" in data.get("data", {}):
|
if "btcPlusRewardByAddress" in data.get("data", {}):
|
||||||
@@ -240,19 +240,18 @@ def save_to_csv(data, filename="btc_plus_rewards.csv"):
|
|||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
|
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
print(f"数据已成功保存到 {filename}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"保存到CSV时出错: {e}")
|
logger.error("保存到CSV时出错: %s", e)
|
||||||
|
|
||||||
|
|
||||||
# 初始化日志
|
# 初始化日志
|
||||||
def setup_logging():
|
def setup_logging():
|
||||||
|
"""配置日志记录,只记录错误信息"""
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.WARNING, # 只记录WARNING及以上级别
|
||||||
format="%(asctime)s - %(levelname)s - %(message)s",
|
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.FileHandler(LOG_FILE, encoding="utf-8"),
|
logging.FileHandler(LOG_FILE, encoding="utf-8"),
|
||||||
logging.StreamHandler(),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
return logging.getLogger(__name__)
|
return logging.getLogger(__name__)
|
||||||
@@ -264,7 +263,7 @@ def git_commit_and_push():
|
|||||||
try:
|
try:
|
||||||
subprocess.run(["git", "add", "."], check=True)
|
subprocess.run(["git", "add", "."], check=True)
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["git", "commit", "-m", f"Auto update BTC Plus data at {datetime.now()}"],
|
["git", "commit", "-m", f"Auto update at {datetime.now()}"],
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
subprocess.run(["git", "push"], check=True)
|
subprocess.run(["git", "push"], check=True)
|
||||||
|
Reference in New Issue
Block a user