Skip to content

Commit

Permalink
Initial Commit 🎉
Browse files Browse the repository at this point in the history
Add listening time calculator, readme and gitignore
  • Loading branch information
yussufbiyik committed May 20, 2021
0 parents commit 77c95c1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions listening_time_calculator.py
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!')
15 changes: 15 additions & 0 deletions readme.md
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.
1 change: 1 addition & 0 deletions your-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json

0 comments on commit 77c95c1

Please sign in to comment.