-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add listening time calculator, readme and gitignore
- Loading branch information
0 parents
commit 77c95c1
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import json, pathlib | ||
|
||
total_listening_time = [] # A variable to collect each milisecond of listening time | ||
|
||
try: # Going through each StreamingHistory file and gathering listening time data for each song | ||
for path in pathlib.Path('your-data').iterdir(): | ||
if path.is_file(): | ||
if path.name.startswith('StreamingHistory'): | ||
print('Going through {}'.format(path.name)) | ||
currentFile = open(path, 'r', encoding='UTF-8') | ||
for item in json.loads(currentFile.read()): | ||
total_listening_time.append(item) | ||
currentFile.close() | ||
finally: # Calculating total listening time | ||
total = 0 | ||
for item in total_listening_time: | ||
total += int(item['msPlayed']) | ||
print(f'Your total listening time is {total/3600000:.2f} hours which is {total/86400000:.2f} days!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# How Much Time You Spent On Listening Spotify ? | ||
Honestly i was wondering this question for sometime and finally decided to make a python script to answer this question. There are easier ways of learning your listening time like downloading an app on your phone but i just wanted to make my own version. | ||
|
||
In this readme file i will be teaching you how to get your data from Spotify and learn your listening time. | ||
## How to get your listening data from Spotify? | ||
1. To get your data go to this adress https://www.spotify.com/us/account/privacy/ | ||
|
||
2. Request your data by following the steps under 'Download your data' headline. | ||
|
||
## How to calculate your total listening time? | ||
1. Download your data by going to your mailbox and finding the mail from Spotify that contains your data. | ||
|
||
2. Open the file and go to 'MyData' and select every file that starts with 'StreamingHistory' and put them in the folder named 'your-data' in the folder of script. You can also put every file in there too but this looks better | ||
|
||
3. Open the script, after running the script, it will print a line that contains your listening time data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.json |