Skip to content

Commit

Permalink
Added fetch data workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
johc committed Mar 27, 2024
1 parent 75d809c commit 722e937
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/fetch_data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Fetch MongoDB Data

on:
schedule:
- cron: '0 0 * * 0' # This sets it to run weekly on Sunday at midnight

jobs:
fetch_data:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install MongoDB client
run: |
python -m pip install --upgrade pip
pip install pymongo
- name: Fetch Data from MongoDB
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
run: |
python fetch_data.py
# Commit and Push changes
- name: Commit and Push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add -A
git commit -m "Update data files" || true
git push origin gh-pages
15 changes: 15 additions & 0 deletions fetch_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pymongo import MongoClient
import json
import os

# Connect to MongoDB
client = MongoClient(os.environ['MONGODB_URI'])
db = client.your_database_name # Replace with your database name

# Fetch data from a collection
collection = db.your_collection_name # Replace with your collection name
data = list(collection.find({}))

# Save to a JSON file
with open('data.json', 'w') as file:
json.dump(data, file)

0 comments on commit 722e937

Please sign in to comment.