Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fcf9b977fb | |||
| bcf209b37f | |||
| 38bdef0e71 | |||
| d5a9b55c92 | |||
| 1a16da265f | |||
| 837fc10d7d | |||
| 01ecc6f2c2 | |||
| b275db54e6 | |||
| c0955b300d | |||
| fb6689555c | |||
| e66596101a |
@ -3,18 +3,22 @@ name: Build and Push Docker Image
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main # 只在 main 分支推送时触发
|
||||
tags:
|
||||
- v* # 推送 v* 标签时也触发(如 v1.0.0)
|
||||
- dev-*
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: 检出代码
|
||||
uses: https://gitea.com/actions/checkout@v3
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
- 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
|
||||
@ -19,7 +19,7 @@ RUN chmod 0644 /etc/cron.d/cronjob && \
|
||||
|
||||
# 安装Python依赖(如果有)
|
||||
COPY ./requirements.txt /app/requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
# 创建日志文件(用于cron输出)
|
||||
RUN touch /var/log/cron.log
|
||||
|
||||
6
cronjob
6
cronjob
@ -1,2 +1,4 @@
|
||||
# 设置每天 14:45 执行
|
||||
45 14 * * * root /usr/local/bin/python /app/main.py >> /var/log/cron.log 2>&1
|
||||
# 开市每小时执行
|
||||
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
|
||||
|
||||
23
day.py
Normal file
23
day.py
Normal file
@ -0,0 +1,23 @@
|
||||
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
Normal file
16
hour.py
Normal file
@ -0,0 +1,16 @@
|
||||
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)
|
||||
3
main.py
3
main.py
@ -1,6 +1,5 @@
|
||||
import akshare as ak
|
||||
import sh000300
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(ak.__version__)
|
||||
sh000300.day()
|
||||
|
||||
15
sz159745.py
Normal file
15
sz159745.py
Normal file
@ -0,0 +1,15 @@
|
||||
import akshare as ak
|
||||
|
||||
def fund():
|
||||
# 获取建材ETF(159745)的最新行情
|
||||
df = ak.fund_etf_hist_sina(symbol="sz159745")
|
||||
latest_price = df.iloc[-1]["close"] # 最新收盘价
|
||||
print(f"建材ETF(159745)最新报价:{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
Normal file
61
util.py
Normal file
@ -0,0 +1,61 @@
|
||||
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}")
|
||||
Loading…
Reference in New Issue
Block a user