Get IP2Location-Lite database #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Get IP2Location-Lite database | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 2 * *" | |
env: | |
RELEASE_NAME: $(date +%Y%m%d%H%M) | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install csvkit | |
- name: Get IP2Location-Lite database | |
env: | |
DOWNLOAD_TOKEN: ${{ secrets.IP2LOCATION_DOWNLOAD_TOKEN }} | |
run: | | |
curl -sSL "https://www.ip2location.com/download/?token=${DOWNLOAD_TOKEN}&file=DB1LITE" -o IP2LOCATION-LITE-DB1.CSV.ZIP | |
curl -sSL "https://www.ip2location.com/download/?token=${DOWNLOAD_TOKEN}&file=DB1LITEIPV6" -o IP2LOCATION-LITE-DB1.IPV6.CSV.ZIP | |
unzip IP2LOCATION-LITE-DB1.CSV.ZIP -d IP2LOCATION-LITE-DB1 | |
unzip IP2LOCATION-LITE-DB1.IPV6.CSV.ZIP -d IP2LOCATION-LITE-DB1.IPV6 | |
- name: Get ip2location-csv-converter script | |
run: curl -sSLO https://raw.githubusercontent.com/ip2location/ip2location-python-csv-converter/master/ip2location-csv-converter.py | |
- name: Convert database from numeric to cidr | |
run: | | |
python ip2location-csv-converter.py -cidr -replace IP2LOCATION-LITE-DB1/IP2LOCATION-LITE-DB1.CSV IP2LOCATION-LITE-DB1.CIDR.CSV | |
python ip2location-csv-converter.py -cidr -replace IP2LOCATION-LITE-DB1.IPV6/IP2LOCATION-LITE-DB1.IPV6.CSV IP2LOCATION-LITE-DB1.IPV6.CIDR.CSV | |
- name: Extract IR IPs | |
run: | | |
csvgrep -c 2 -m "IR" IP2LOCATION-LITE-DB1.CIDR.CSV | csvcut -c 1 | sed '1d' > ip2location-ir.txt | |
csvgrep -c 2 -m "IR" IP2LOCATION-LITE-DB1.IPV6.CIDR.CSV | csvcut -c 1 | sed '/ffff/d' > ip2location-ir6.txt | |
- name: Push assets to ip2location branch | |
run: | | |
mkdir -p ip2location | |
cp ip2location-ir.txt ip2location-ir6.txt ip2location | |
cd ip2location || exit 1 | |
git init | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git checkout -b ip2location | |
git add . | |
git commit -m "${{ env.RELEASE_NAME }}" | |
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" | |
git push -f origin ip2location |