Compare commits

..

No commits in common. "dev-0.1" and "master" have entirely different histories.

8 changed files with 14 additions and 134 deletions

View File

@ -3,22 +3,18 @@ name: Build and Push Docker Image
on:
push:
branches:
- dev-*
- main # 只在 main 分支推送时触发
tags:
- v* # 推送 v* 标签时也触发(如 v1.0.0
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: https://gitea.com/actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v4
- name: 镜像构建
run: |
docker build -t ak13:latest .
# 可以检查镜像是否构建成功
docker images
- name: 直接启动服务
run: |
docker rm -vf ak13 || true
docker run -d --name ak13 --workdir /app -e TZ=Asia/Shanghai -v ak13-logs:/app/logs ak13:latest
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .

View File

@ -19,7 +19,7 @@ RUN chmod 0644 /etc/cron.d/cronjob && \
# 安装Python依赖如果有
COPY ./requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install -r requirements.txt
# 创建日志文件用于cron输出
RUN touch /var/log/cron.log

View File

@ -1,4 +1,2 @@
# 开市每小时执行
0 * * * * root /usr/local/bin/python /app/hour.py 2>&1 | tee -a /var/log/cron.log /app/log/cron.log
# 每天 14:45 执行
45 14 * * * root /usr/local/bin/python /app/day.py 2>&1 | tee -a /var/log/cron.log /app/log/cron.log
# 设置每天 14:45 执行
45 14 * * * root /usr/local/bin/python /app/main.py >> /var/log/cron.log 2>&1

23
day.py
View File

@ -1,23 +0,0 @@
import datetime
import akshare as ak
import pushplus
import sz159745
import util
if __name__ == '__main__':
print(ak.__version__)
now = datetime.datetime.now()
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}")
# flag = util.is_trading_time_akshare()
# print(f"是否为开市时间: {'是' if flag else '否'}")
# if flag:
cost = "0.66"
price = sz159745.price()
print("sz159745 price:", price)
pushplus.send_msg(now.strftime('%Y-%m-%d %H:%M:%S'),
f"sz159745 cost {cost} price: {price}"
)

16
hour.py
View File

@ -1,16 +0,0 @@
import datetime
import akshare as ak
import sz159745
import util
if __name__ == '__main__':
print(ak.__version__)
now = datetime.datetime.now()
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}")
flag = util.is_trading_time_akshare()
print(f"是否为开市时间: {'' if flag else ''}")
price = sz159745.price()
print("sz159745 price:", price)

View File

@ -1,5 +1,6 @@
import akshare as ak
import sh000300
if __name__ == '__main__':
print(ak.__version__)
sh000300.day()

View File

@ -1,15 +0,0 @@
import akshare as ak
def fund():
# 获取建材ETF159745的最新行情
df = ak.fund_etf_hist_sina(symbol="sz159745")
latest_price = df.iloc[-1]["close"] # 最新收盘价
print(f"建材ETF159745最新报价{latest_price}")
def price():
df = ak.stock_individual_spot_xq(symbol="sz159745")
latest_price = df.query("item == '现价'")["value"].values[0]
return latest_price
if __name__ == '__main__':
price()

61
util.py
View File

@ -1,61 +0,0 @@
import datetime
import akshare as ak
def is_trading_time_akshare(current_time=None):
"""
使用akshare判断当前是否为A股开市时间包括交易日和交易时段
参数:
current_time: 待判断的时间默认为当前时间
返回:
bool: 是否为开市状态
"""
if current_time is None:
current_time = datetime.datetime.now()
# 获取当前日期字符串YYYY-MM-DD
current_date_str = current_time.strftime("%Y-%m-%d")
# 获取A股历史交易日数据包含所有交易日
trade_dates = ak.tool_trade_date_hist_sina()
# 1. 判断是否为交易日
is_trading_day = current_date_str in trade_dates["trade_date"].values
if not is_trading_day:
return False
# 2. 判断是否在交易时间段内
# 上午9:30-11:30下午13:00-15:00
current_time_of_day = current_time.time()
morning_start = datetime.time(9, 30)
morning_end = datetime.time(11, 30)
afternoon_start = datetime.time(13, 0)
afternoon_end = datetime.time(15, 0)
in_morning = morning_start <= current_time_of_day <= morning_end
in_afternoon = afternoon_start <= current_time_of_day <= afternoon_end
return in_morning or in_afternoon
if __name__ == "__main__":
now = datetime.datetime.now()
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"是否为开市时间: {'' if is_trading_time_akshare() else ''}")
# 测试特定时间
test_times = [
datetime.datetime(2023, 10, 9, 10, 0), # 交易日上午
datetime.datetime(2023, 10, 9, 14, 0), # 交易日下午
datetime.datetime(2023, 10, 9, 8, 0), # 交易日前早
datetime.datetime(2023, 10, 7, 10, 0), # 周六
datetime.datetime(2023, 10, 1, 10, 0), # 国庆假期
]
print("\n测试特定时间:")
for test_time in test_times:
status = "" if is_trading_time_akshare(test_time) else ""
print(f"{test_time.strftime('%Y-%m-%d %H:%M')}: {status}")