Update File with API Data #27312
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 File with API Data | |
on: | |
schedule: | |
- cron: '*/5 * * * *' # Runs every 5 minutess | |
push: | |
branches: | |
- main | |
jobs: | |
update-file: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Fetch Data from API | |
run: | | |
API_DATA=$(curl -s "https://www.udemy.com/api-2.0/courses/4460762/?fields%5Bcourse%5D=num_subscribers") | |
echo "API Data: $API_DATA" | |
CSV_DATA=$(echo "$API_DATA" | jq -r '[{"subscribers": .num_subscribers}] | (.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv') | |
echo "CSV Data: $CSV_DATA" | |
echo "$CSV_DATA" > api_data.csv | |
- name: Commit and Push Changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: "Update data from API" | |
commit_user_name: "GitHub Actions" | |
commit_user_email: "actions@github.com" |