-
Notifications
You must be signed in to change notification settings - Fork 13
56 lines (47 loc) · 1.72 KB
/
run-selenium-script.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
name: 运行新闻抓取脚本
on:
push:
branches:
- main # 在推送到 main 分支时运行
schedule:
- cron: '0 */2 * * *' # 每两小时的第0分钟执行
workflow_dispatch: # 允许手动触发
jobs:
setup-and-test:
runs-on: ubuntu-latest # 使用 Ubuntu 环境
steps:
- name: 检出代码库
uses: actions/checkout@v4
with:
persist-credentials: true # 确保能够推送更改
- name: 设置 Python 环境
uses: actions/setup-python@v5
with:
python-version: '3.x' # 指定最新的 Python 3 版本
- name: 设置 Git 配置
run: |
git config --global user.name "NowScott"
git config --global user.email "[email protected]"
- name: 安装 Chrome
run: |
sudo apt-get update
sudo apt-get install -y wget unzip
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb || sudo apt-get -f install -y
- name: 安装 Python 依赖
run: |
python -m pip install --upgrade pip
pip install selenium webdriver-manager chromedriver-autoinstaller
- name: 运行新闻抓取脚本
run: |
python src/script.py # 执行新闻抓取脚本,确保脚本路径正确
- name: 提交并推送更改
run: |
git add news_archive/
git diff --cached --exit-code news_archive/ || (
DATE=$(TZ="Asia/Shanghai" date "+%Y-%m-%d %H:%M:%S")
echo "正在提交更改..."
git commit -m "更新新闻文件于 $DATE"
git push origin main
echo '更新成功'
)