Want to stay on top of your favorite crypto's price, but tired of manual checks? This guide empowers you to build an automated Cryptocurrency Price Tracker with GitHub Codespaces, a cloud-based development environment, and GitHub Actions, for commit automation. Let's dive in!
** Step 1: Secure Your Crypto Vault (Repository)**
- Head to GitHub and create a new private repository (e.g., "Cryptocurrency-Price-Tracker").
- Name it wisely, reflecting your crypto passion!
** Step 2: Enter the Codespace Arena**
- Open your new repository and click "Code" -> "Codespaces" -> "Create codespace on main".
- This unlocks your cloud-based development playground. Time to code!
** Step 3: Craft Your Price-Fetching Spell (Script)**
- In your codespace, conjure a
tracker.py
file. - Let's use Python and CoinGecko API to extract the desired crypto's price:
import requests
def get_crypto_price(symbol):
url = f"https://api.coingecko.com/api/v3/simple/price?ids={symbol}&vs_currencies=usd"
response = requests.get(url)
data = response.json()
return data[symbol]['usd']
print(get_crypto_price('bitcoin'))
** Step 4: Automate the Price Updates (GitHub Actions)**
- Click the "Actions" tab and select "New workflow".
- Choose the "Python application" template for streamlined setup.
- Replace the
main.yml
file with this magic formula:
name: Daily Crypto Price Update
on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight (UTC)
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Run the script
run: python tracker.py
- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git diff-index --quiet HEAD || git commit -m "Update crypto price"
git push
** Step 5: Unleash the Automation!**
- Commit and push your code to the
main
branch. - Visit the "Actions" tab and witness your workflow springing to life, updating prices daily!
Remember:
- Adjust the script for your desired cryptocurrency.
- Replace
'bitcoin'
with its symbol.
Now you have a self-updating Cryptocurrency Price Tracker, powered by the magic of GitHub! Feel free to customize and explore further!
P.S.: A simple project to wish all of you: Happy coding!
Top comments (0)