-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (71 loc) · 2.86 KB
/
test_scraper.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Run Scraper Daily
# Set the schedule to run every 24 hours
# on:
# schedule:
# - cron: "0 0 * * *" # This runs at midnight UTC every day
#testing
# Set the schedule to run every 5 minutes
on:
push:
branches:
- scraper-tecq
schedule:
- cron: "*/5 * * * *" # This runs every 5 minutes
workflow_dispatch: # This allows you to run the workflow manually
jobs:
run-scraper:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.13' # Use your required Python version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install Chrome
run: |
sudo apt-get update
sudo apt-get install -y google-chrome-stable
- name: Install ChromeDriver
run: |
# Get the major version of the installed Chrome
CHROME_VERSION=$(google-chrome --version | grep -oP '\d+\.\d+' | head -1)
echo "Installed Chrome major version is $CHROME_VERSION"
# Find the closest ChromeDriver version available for this major version
CHROMEDRIVER_VERSION=$(curl -sS "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION" || echo "")
if [ -z "$CHROMEDRIVER_VERSION" ]; then
echo "No matching ChromeDriver version found for Chrome $CHROME_VERSION."
exit 1
fi
echo "Installing ChromeDriver version $CHROMEDRIVER_VERSION"
curl -Lo /tmp/chromedriver.zip "https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
sudo apt-get install -y unzip
sudo unzip /tmp/chromedriver.zip -d /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver
- name: Run Scraper
env:
CHROME_BIN: "/usr/bin/google-chrome" # Optional, in case your script needs the Chrome path
CHROMEDRIVER_PATH: "/usr/local/bin/chromedriver"
run: |
python main.py
- name: Save Excel Output
# Create a file name with the date and time
run: |
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
mv output.xlsx "output_$timestamp.xlsx"
mv "output_$timestamp.xlsx" results/
- name: Commit and Push the Excel file
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add results/output_*.xlsx
git commit -m "Add data for $timestamp"
git push --force
env:
# GitHub Token for permissions to push
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# make sure to push to scraper-tecq branch