Skip to content

Commit

Permalink
checking the latest files
Browse files Browse the repository at this point in the history
  • Loading branch information
mcam10 committed Dec 21, 2024
2 parents 0268882 + dcede41 commit 6f4f690
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 29 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,3 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Get Secrets
uses: mobiledevops/secret-to-file-action@v1
with:
base64-encoded-secret: ${{ secrets.SERVICE_ACCOUNT }}
filename: decisive-fabric-155319-3dcd7ac1c659.json
working-directory: "."

- name: Run Docker image
uses: addnab/docker-run-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ${{ env.REGISTRY }}
image: ${{ steps.meta.outputs.tags }}
shell: python
run: |
"gdrive_sync_to_s3.py"
28 changes: 17 additions & 11 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ name: Sync Gdrive AWS S3

on:
workflow_dispatch:

env: # Or as an environment variable
AccessKey: ${{ secrets.ACCESSKEY }}
Secretaccesskey: ${{ secrets.SECRETSACCESSKEY }}
SERVICE_ACCOUNT_FILE: ${{ secrets.SERVICE_ACCOUNT_FILE }}
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

jobs:
build-and-push-image:
sync-to-s3:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Checkout repository
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Inject Secrets to Directory
uses: mobiledevops/secret-to-file-action@v1
with:
base64-encoded-secret: ${{ secrets.SERVICE_ACCOUNT }}
filename: decisive-fabric-155319-3dcd7ac1c659.json
working-directory: "."
working-directory: "/home/runner/work/python-pipelines/python-pipelines/gdrive-aws-sync-workflow"
# Has to be a better way to do this DRY
- name: Inject Secrets to Directory
uses: mobiledevops/secret-to-file-action@v1
with:
base64-encoded-secret: ${{ secrets.ENV }}
filename: decisive-fabric-155319-3dcd7ac1c659.json
working-directory: "."

- name: Lets run some python code
uses: actions/setup-python@v5
with:
python-version: '3.9'
filename: .env
working-directory: "/home/runner/work/python-pipelines/python-pipelines/gdrive-aws-sync-workflow"
- run: |
pip install -r requirements.txt
python gdrive_sync_to_s3.py
ls -lah
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
66 changes: 66 additions & 0 deletions spotify-workflow/ollama_python_run.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ollama run llama3
>>> Write me python code to connect to the spotify web playback api to play songs
Here's a Python script that connects to Spotify's Web Playback API and plays songs:
```python
import requests
import json
import time

# Set your Spotify client ID, secret, and redirect URI
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
redirect_uri = "YOUR_REDIRECT_URI"

# Set the scope and grant type for authentication
scope = "user-library-read playlist-read-private"
grant_type = "client_credentials"

# Get an access token using your client ID and secret
auth_response = requests.post(
f"https://accounts.spotify.com/api/token",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=f"grant_type={grant_type}&client_id={client_id}&client_secret={client_secret}",
)

access_token = json.loads(auth_response.text)["access_token"]

# Set the Spotify API endpoint and parameters
endpoint = "https://api.spotify.com/v1/playlists"
params = {"offset": 0, "limit": 50}

# Get a list of playlists using your access token
playlists_response = requests.get(endpoint, params=params, headers={"Authorization": f"Bearer
{access_token}"])

# Parse the JSON response and get the first playlist's ID
playlist_id = json.loads(playlists_response.text)["items"][0]["uri"].split(":")[-1]

# Set the endpoint for getting tracks from a playlist
tracks_endpoint = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"

# Get the tracks from the playlist using your access token
tracks_response = requests.get(tracks_endpoint, params=params, headers={"Authorization": f"Bearer
{access_token}"})

# Parse the JSON response and get the first track's ID
track_id = json.loads(tracks_response.text)["items"][0]["uri"].split(":")[-1]

# Set the endpoint for playing a track
play_endpoint = "https://api.spotify.com/v1/me/player"

# Set the request body to play the track
play_request_body = {"context_uri": f"spotify:track:{track_id}", "position_ms": 0}

# Play the track using your access token
play_response = requests.put(play_endpoint, json=play_request_body, headers={"Authorization":
f"Bearer {access_token}"})

print("Playing song...")
```
This script does the following:

1. Authenticates with Spotify's API using a client ID and secret.
2. Retrieves a list of playlists for the authenticated user.
3. Gets the ID of the first playlist and uses it to retrieve its tracks.
4. Gets the ID of the first track in the playlist and sets up the request body to play it.
5. Sends the request to start playing the track using the access token.

0 comments on commit 6f4f690

Please sign in to comment.