Skip to content

Update Pageload metrics #11

Update Pageload metrics

Update Pageload metrics #11

name: Update Pageload metrics
on:
workflow_dispatch:
schedule:
- cron: '30 23 * * *' # Runs daily at 11:30 PM
jobs:
merge-json:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Required Python Packages
run: |
python -m pip install --upgrade pip
pip install requests pandas
- name: Download and Merge JSON Files
run: |
python <<EOF
import requests
import pandas as pd
urls = [
"https://sql.telemetry.mozilla.org/api/queries/101647/results.json?api_key=lTPLgqu2UNPA1XxCz0dbayVAN4rGjNvTAmLU5WBV",
"https://sql.telemetry.mozilla.org/api/queries/101653/results.json?api_key=OtucZwTAEGY7SBgdLlgWtQPXvPQF4TaXGLzLUq8n",
"https://sql.telemetry.mozilla.org/api/queries/101616/results.json?api_key=uc7V76QeZ3FT94y0GPeg8YZkdtaJTEKqNGUtaT19"
]
all_data = []
for url in urls:
response = requests.get(url)
data = response.json()
rows = data.get("query_result", {}).get("data", {}).get("rows", [])
all_data.extend(rows)
try:
with open('pageload-metrics-data.json', 'r') as file:
existing_data = pd.read_json(file)
all_data.extend(existing_data.to_dict(orient='records'))
except FileNotFoundError:
raise FileNotFoundError("Error: 'pageload-metrics-data.json' not found.")
df = pd.DataFrame(all_data)
df['date'] = pd.to_datetime(df['date']).dt.strftime('%Y-%m-%d')
df = df.drop_duplicates(subset=['date', 'channel', 'os', 'metric'], keep='last')
df = df.sort_values(by='date')
df.to_json('pageload-metrics-data.json', orient='records')
EOF
- name: Commit and Push Changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add pageload-metrics-data.json
git commit -m "Update pageload-metrics-data.json with latest data"
git push