spotify-playlist-exporter 0.0.3
A small example package
Requires Python: >=3.7

# Spotify Playlist Exporter

This Python package allows you to export your Spotify playlists and recently played tracks as an Excel file. It uses the Spotipy library to interact with the Spotify Web API.

## Prerequisites

Before you can use the package, you'll need to install the following Python packages:

- Spotipy
- pandas

You can install them with the following command:

```bash
pip install spotipy pandas openpyxl
```

## Setting up Spotify API credentials

To access the Spotify API, you need to have API credentials in the form of a `client_id`, `client_secret`, and a `redirect_uri`. Here's how you can get your credentials:

1. Go to the Spotify Developer Dashboard: https://developer.spotify.com/dashboard/
2. Log in with your Spotify account or create a new one if you don't have one yet.
3. Click on "Create an App" and fill in the required information.
4. After creating the app, you will see your `client_id` and `client_secret` in the app's Dashboard.
5. Set the `redirect_uri` for your app by clicking "Edit Settings" and adding a redirect URI, such as "http://localhost:9000".

Now that you have your credentials, you can store them in a `cred.py` file in the same directory as the main script. The `cred.py` file should look like this:

```python
client_id = "your_client_id"
client_secret = "your_client_secret"
redirect_uri = "your_redirect_uri"
username = "your_spotify_username"
```

Replace the placeholder values with your actual credentials and Spotify username.

## Package usage

The package contains several functions to interact with your Spotify playlists and recently played tracks. You can use it as a standalone script or import the functions in your own Python project.

### Main function

The `main` function is the entry point of the script. It takes three optional arguments:

- `playlists_file`: The filename prefix for the exported playlists Excel file (default: 'playlists').
- `recently_file`: The filename prefix for the exported recently played tracks Excel file (default: 'recently_played').
- `date_string`: The date string in 'yyyy-mm-dd' format from which to fetch recently played tracks (default: '2023-01-01').

To run the script, you can use the following command:

```bash
python script_name.py --playlistsfile playlists_xx --recentlyfile recently_played_xy --datestring 2023-01-01
```

Replace `script_name.py` with the name of the main script file.

### Exporting playlists

The `export_spotify_playlists` function fetches your playlists and their tracks. It returns a dictionary containing the playlist titles and their respective track lists.

### Exporting recently played tracks

The `recently_played` function fetches the tracks you've recently played, limited to the last 50 tracks. You can pass a Unix timestamp to filter the tracks played after a certain date.

### Saving playlists and recently played tracks as Excel files

The `playlists_to_dataframe` and `recently_played_to_dataframe` functions convert the fetched data into pandas DataFrames, which can be saved as Excel files. By default, the script will save the Excel files with a timestamp in the format "yymmdd_HHMMSS" as a prefix.

## Example usage

Here's an example of how to run the script:

```bash
python script_name.py --playlistsfile my_playlists --recentlyfile my_recently_played --datestring 2023-01-01
```

This command will generate two Excel files with names like "220101_122345_my_playlists.xlsx