diff --git a/listening_time_calculator.py b/listening_time_calculator.py new file mode 100644 index 0000000..4a963e9 --- /dev/null +++ b/listening_time_calculator.py @@ -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!') \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..bbbe842 --- /dev/null +++ b/readme.md @@ -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. \ No newline at end of file diff --git a/your-data/.gitignore b/your-data/.gitignore new file mode 100644 index 0000000..94a2dd1 --- /dev/null +++ b/your-data/.gitignore @@ -0,0 +1 @@ +*.json \ No newline at end of file