Skip to content

Commit

Permalink
Added timezone conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
DelChaRay committed Jan 1, 2022
1 parent 71a35f1 commit bc861d9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ First of all you need to download your Spotify detailed data from the [Spotify p
2. Unzip.
3. Run SpotifyRewrappedGUI.exe
4. Fill the input path (path where your StreamingHistory.json is located) and the output path (where spotify-rewrapped.png will be generated)
5. Generate
5. Optionally, fill out your timezone with quotes (otherwise defaults to UTC). [Wikipedia listed timezones under 'TZ Database Name' column.](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
6. Generate

## On Linux
1. You need to clone this repo (or download as ZIP) and run the python code.
Expand All @@ -26,9 +27,9 @@ First of all you need to download your Spotify detailed data from the [Spotify p
```
3. Run linux.py
```bash
python3 ./linux.py <input_path> <output_path>
python3 ./linux.py <input_path> <output_path> <timezone>
```
for example:
```bash
python3 ./linux.py /mnt/d/spotify_data /mnt/d/images
python3 ./linux.py /mnt/d/spotify_data /mnt/d/images 'US/Pacific'
```
4 changes: 2 additions & 2 deletions data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class DataManager:
"""It's main responsability is to store the input data and allow querying it"""
def __init__(self, files=None):
def __init__(self, files=None, timezone='UTC'):
# Read input files
self.df = pd.DataFrame()
for file in files:
Expand All @@ -13,7 +13,7 @@ def __init__(self, files=None):
self.df = pd.concat([self.df, data_frame], axis=0)

# Filter and process data
self.df.endTime = pd.to_datetime(self.df.endTime)
self.df.endTime = pd.to_datetime(self.df.endTime).dt.tz_localize('UTC').dt.tz_convert(timezone)
self.df = self.df[self.df.endTime.dt.year == 2021]
self.df = self.df[self.df.msPlayed > 10000]

Expand Down
3 changes: 2 additions & 1 deletion linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

input_path = sys.argv[1]
output_file = sys.argv[2] + '/spotify-rewrapped.png'
timezone = sys.argv[3] if len(sys.argv) == 4 else 'UTC'

SpotifyRewrapped(path=input_path, output=output_file)
SpotifyRewrapped(path=input_path, output=output_file, timezone=timezone)
5 changes: 3 additions & 2 deletions spotify_rewrapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
class SpotifyRewrapped:
"""Spotify Rewrapped. Main class"""

def __init__(self, path, output):
def __init__(self, path, output, timezone='UTC'):
self.path = path
self.output = output
self.timezone = timezone
self.generate()
self.cleanup()

Expand All @@ -22,7 +23,7 @@ def generate(self):
pg = PlotGenerator(path=self.path,
style='./resources/spotify.mplstyle',
font='./resources/gotham-medium.otf')
dm = DataManager(glob.glob(f'{self.path}/StreamingHistory[0-9].json'))
dm = DataManager(glob.glob(f'{self.path}/StreamingHistory[0-9].json'), timezone=self.timezone)

# Top artists by hours_played
top = dm.get_top_n_artists(20)
Expand Down

0 comments on commit bc861d9

Please sign in to comment.