Update Trackers Data #28
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: Update Trackers Data | |
on: | |
workflow_dispatch: # Allow manual triggering | |
schedule: | |
- cron: "0 0 * * 0" # Schedule to run every Sunday at midnight UTC (optional) | |
jobs: | |
exodus_data: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Download JSON file | |
run: | | |
wget -O trackers.json https://reports.exodus-privacy.eu.org/api/trackers | |
- name: Parse JSON and create Android resource file | |
run: | | |
python - <<EOF | |
import json | |
json_file = 'trackers.json' | |
output_file = 'trackers.xml' | |
# Format the JSON file | |
with open(json_file, "r+", encoding="utf8") as file: | |
json_content = json.load(file) | |
json_content = json.dumps(json_content, indent=4, sort_keys=True) | |
file.seek(0) | |
file.write(json_content) | |
# Read the JSON file | |
with open(json_file, "r", encoding="utf8") as file: | |
json_content = json.load(file) | |
# Sort the JSON file by code_signature | |
json_content["trackers"] = \ | |
dict(sorted(json_content["trackers"].items(), key=lambda x: x[1]["code_signature"])) | |
# Extract the trackers tags | |
signatures = [] | |
for tracker in json_content['trackers'].values(): | |
try: | |
if '|' in tracker['code_signature']: | |
for signature in tracker['code_signature'].split('|'): | |
signatures.append(signature) | |
else: | |
signatures.append(tracker['code_signature']) | |
except KeyError: | |
pass | |
websites = [tracker['website'] for tracker in json_content['trackers'].values()] | |
names = [tracker['name'] for tracker in json_content['trackers'].values()] | |
# Format the output | |
output = f'<?xml version="1.0" encoding="utf-8"?>\n\n' | |
output += '<!--suppress CheckTagEmptyBody -->\n' | |
output += '<resources>\n\n' | |
output += f'<!-- This file is auto-generated by the actions script. -->\n\n' | |
output += f'<!-- Total trackers: {len(signatures)} -->\n\n' | |
output += '\t<string-array name="trackers">\n' | |
output += '\n'.join([f'\t\t<item>{signature}</item> <!-- {signatures.index(signature) + 1} -->' for signature in signatures]) | |
output += '\n\t</string-array>\n' | |
output += f'\n<!-- Total websites: {len(websites)} -->\n\n' | |
output += '\t<string-array name="websites">\n' | |
output += '\n'.join([f'\t\t<item>{website}</item> <!-- {websites.index(website) + 1} -->' for website in websites]) | |
output += '\n\t</string-array>\n' | |
output += f'\n<!-- Total names: {len(names)} -->\n\n' | |
output += '\t<string-array name="names">\n' | |
output += '\n'.join([f'\t\t<item>{name}</item> <!-- {names.index(name) + 1} -->' for name in names]) | |
output += '\n\t</string-array>\n\n' | |
output += '</resources>' | |
# Write the output to the xml file | |
with open(output_file, 'w') as file: | |
file.write(output) | |
EOF | |
- name: Move Android resource file | |
run: | | |
if [ ! -d "./app/src/main/res/values/" ]; then | |
mkdir -p ./app/src/main/res/values/ | |
fi | |
if [ -f "trackers.xml" ]; then | |
echo "File exists, moving..." | |
fi | |
mv trackers.xml ./app/src/main/res/values/ | |
if [ -f "./app/src/main/res/values/trackers.xml" ]; then | |
echo "File moved successfully." | |
fi | |
- name: Cleanup | |
run: | | |
rm -f trackers.json | |
# Check for changes | |
- name: Check for changes | |
id: git-status | |
run: | | |
export GIT_STATUS=$(git status --porcelain) | |
echo "GIT_STATUS=$GIT_STATUS" >> $GITHUB_ENV | |
if [ -z "$GIT_STATUS" ]; then | |
echo "No changes detected..." | |
fi | |
# Commit changes to the repo | |
- name: Commit changes | |
if: env.GIT_STATUS != '' | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
git add . | |
git commit -m "Automated Exodus data update" | |
git push origin master |