Skip to content

Commit

Permalink
GitHub Actions Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Prem-ium authored Jan 6, 2024
1 parent 1ec5fc7 commit e89f09c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ APPRISE_ALERTS=
# Values: Any valid IANA timezone (https://www.iana.org/time-zones)
TZ='America/New_York'

# Description: Whether you are using GitHub Actions or not
# Type: Boolean
GITHUB_ACTIONS=False

# Description: For GitHub Actions use.
# Type: String of JSON
AUTH_CACHE='
{"access_token": "access-code-here",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "refresh-token-here",
"scope": "scopes here",
"expires_at": 1705357893
}'

# Description: Google Spreadsheet service account JSON key
# Type: String of JSON
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
- Generate List of Top Played Artists
- Optional Apprise Alerts/Notifications upon Program Execution/Playlist Update
- Google Sheets Compatiable.
- Keep_Alive Flask Server & [Replit](https://replit.com/) compatiable (Run Program 24/7, no computer required)
- GitHub Actions
- Keep_Alive Flask Server
- Docker Support (In Addition to Docker Quickstart Bat File)
- Optional Recommended Tracks & Artists (Seperate Playlist)

Expand All @@ -33,6 +34,8 @@ To run this project, you will need to add the following environment variables to
| `KEEP_ALIVE` | Whether to run the flask server or not to keep the program from sleeping on replit. | False |
| `APPRISE_ALERTS` | Full list of services and their URLs available here: [Apprise Wiki](https://github.com/caronc/apprise/wiki) | - |
| `TZ` | Your desired Time-Zone. Should be formatted from the IANA TZ Database. | `America/New York` |
| `GITHUB_ACTIONS` | Boolean value indicating whether you're running or setting up to use GitHub Actions. | - |
| `AUTH_CACHE` | Cache JSON String retrieved from initial setup, for GitHub Actions. | - |
| `GSPREAD_KEYS` | Your Google Service Account JSON contents obtained via OAuth 2.0 Client ID in Credentials of Google Cloud API. | - |


Expand All @@ -47,7 +50,8 @@ To run this project, you will need to add the following environment variables to
5. Copy/paste Client ID into `CLIENT_ID` and Secret Client ID into `SECRET_CLIENT_ID` within your .env file.
<img src="https://user-images.githubusercontent.com/80719066/202246004-f7307806-69ec-4489-975b-beb71e6637b3.png" style="width: 50%;"></img>

#### Replit (Optional, Recommended)
#### Replit (~~Optional, Recommended~~, Depreciated)
Note: In January 2024, Replit has discontinued support for Always On & Free Hosting.
1. Login/Create a [Replit](https://replit.com/) account and create a new Python repl.
2. Setup .env within Replit's Secret tab (set `KEEP_ALIVE` to True) & go through [Installation](#installation). Optionally, move all files out of folder for ease of navigation, replace empty/old main.py.
3. Run the program and copy URL in the Flask webview. It should be something similar to:
Expand All @@ -67,7 +71,7 @@ This script can be used locally or using Docker.
Clone the repository & Install dependencies
```bash
git clone https://github.com/Prem-ium/Spotify-Wrapped-365.git
cd Spotify-Wrapped365
cd Spotify-Wrapped-365
pip install -r requirements.txt
```
Finally, you're ready to run the script!
Expand Down Expand Up @@ -128,6 +132,6 @@ Thank you for your support!
## Final Remarks
How to Get Spotify Wrapped. 365 days a year. While everyone else google searches 'how to see / check / find spotify wrapped' you'll have access to your top played tracks and artists all year long!

As previously mentioned however, I strongly recommend utilizing this repository using a service such as [Replit](https://replit.com/) & [UpTimeRobot](https://uptimerobot.com/) as they will allow you the program to run without any computer resource cost to you.
~~As previously mentioned however, I strongly recommend utilizing this repository using a service such as [Replit](https://replit.com/) & [UpTimeRobot](https://uptimerobot.com/) as they will allow you the program to run without any computer resource cost to you. ~~

Beyond that, thank you for your interest in this repository. Please leave a 🌟 & share with your friends!
35 changes: 22 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

# Spotify Credentials
if not os.environ["CLIENT_ID"] or not os.environ["SECRET_CLIENT_ID"] or not os.environ["REDIRECT_URL"] or not os.environ["USERNAME"]:
raise Exception(
"Variables are missing within the .env file. Please ensure you have CLIENT_ID, SECRET_CLIENT_ID, REDIRECT_URL, and USERNAME set.")
raise Exception("Variables are missing within the .env file. Please ensure you have CLIENT_ID, SECRET_CLIENT_ID, REDIRECT_URL, and USERNAME set.")
else:
# Update with your own Spotify Credentials (Client ID, Secret Client ID, redirect, and username)
SPOTIPY_CLIENT = os.environ['CLIENT_ID']
Expand All @@ -51,11 +50,25 @@
SCOPE = "user-top-read playlist-modify-private playlist-modify-public user-library-modify user-library-read playlist-read-private ugc-image-upload"
USERNAME = os.environ['USERNAME']

# Initialize Spotify
SP = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=SPOTIPY_CLIENT, client_secret=SPOTIPY_SECRET_CLIENT,
# Get Spotify OAuth token without user input
sp_oauth = SpotifyOAuth(client_id=SPOTIPY_CLIENT, client_secret=SPOTIPY_SECRET_CLIENT,
redirect_uri=SPOTIPY_REDIRECT, scope=SCOPE, username=USERNAME, open_browser=False)
if (os.environ.get("GITHUB_ACTIONS", "false").lower() == "true"):
GITHUB_ACTIONS = True
if os.environ.get('AUTH_CACHE', None) is not None:
token_info = json.loads(os.environ['AUTH_CACHE'])
SP = spotipy.Spotify(auth=token_info['access_token'])
else:
# Aware of the fact that this is not the best way to do this, but it works for now
token_info = sp_oauth.get_access_token()
print(f'Assign the following to the AUTH_CACHE secrets variable, within GitHub Actions Secrets page:\n{token_info}\n\n')
SP = spotipy.Spotify(auth=token_info['access_token'])
else:
GITHUB_ACTIONS = False
SP = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=SPOTIPY_CLIENT, client_secret=SPOTIPY_SECRET_CLIENT,
redirect_uri=SPOTIPY_REDIRECT, scope=SCOPE, username=USERNAME, open_browser=False))
USER_ID = SP.current_user()['id']

# Whether to use keep_alive.py
if (os.environ.get("KEEP_ALIVE", "false").lower() == "true"):
from keep_alive import keep_alive
Expand Down Expand Up @@ -272,17 +285,13 @@ def main():
try:
Wrapped()
print(f'\n{"-"*88}\n{f"{info}".center(88)}\n{"-"*88}\n')
time.sleep(WAIT)

if not GITHUB_ACTIONS: time.sleep(WAIT)
else: break
except Exception as e:
print(f'\Exception:\n{e}\n\n{traceback.format_exc()}\n\n')
if APPRISE_ALERTS:
alerts.notify(title=f'Wrapped365 Exception.',
body=f'{e}\nAttempting to restart in 15 minutes...')
if APPRISE_ALERTS: alerts.notify(title=f'Wrapped365 Exception.', body=f'{e}\nAttempting to restart in 15 minutes...')
time.sleep(900)
continue



if __name__ == '__main__':
if APPRISE_ALERTS:
alerts = apprise_init()
Expand Down

0 comments on commit e89f09c

Please sign in to comment.