Skip to content

Instantly share code, notes, and snippets.

View vlad-ds's full-sized avatar

Vlad Gheorghe vlad-ds

View GitHub Profile
from pandas import DataFrame
def main():
path = 'input/mail.mbox'
mails = get_mails(path)
unsub_links = add_unsubscribe(mails)
df = DataFrame(unsub_links).T
df = df.sort_values(by='count', ascending=False)
df.to_csv('output.csv')
@vlad-ds
vlad-ds / unsub.py
Last active February 3, 2020 16:33
import re
def add_unsubscribe(mails: List, unsub_links: dict = {}) -> dict:
for mail in mails:
#getting sender
sender_line = mail.split('\n')[0] #first line of the mail
sender_words = sender_line.split(' ')[1:] #removes the 'From: ' part
sender = ' '.join(sender_words) #recreates the name string
if 'Q?' in sender:
sender = re.findall('.Q.?(.*?)\?', sender)[0] #removing some char coding
@vlad-ds
vlad-ds / unsub.py
Last active February 3, 2020 16:43
from typing import List
def get_mails(path: str, limit: int = None) -> List[str]:
'''Extract emails from an .mbox file.'''
mails = []
c = -1
mail = str()
with open(path, 'r', encoding = 'UTF-8') as file:
for line in file: #read every line
if c == limit: break
print(token)
>> T2_wi8XsUpJrbD0BHQH4vX0BrSuYV0D88sVrQ_wMgApU...
@vlad-ds
vlad-ds / spoty.py
Last active February 1, 2020 17:26
{
"endTime" : "2019–01–26 07:49",
"artistName" : "Tom Waits",
"trackName" : "Heartattack And Vine",
"msPlayed" : 8850
}
@vlad-ds
vlad-ds / spoty.py
Last active February 1, 2020 17:53
import pandas as pd
df = pd.DataFrame(with_features)
df.to_csv('streaming_history.csv')
@vlad-ds
vlad-ds / spoty.py
Last active February 1, 2020 17:53
streamings = get_streamings()
unique_tracks = list(set([streaming['trackName']
for streaming in streamings]))
all_features = {}
for track in unique_tracks:
track_id = get_id(track, token)
features = get_features(track_id, token)
if features:
all_features[track] = features
@vlad-ds
vlad-ds / spoty.py
Last active February 1, 2020 17:53
lucy_features = get_features(lucy_id, token)
print(lucy_features)
>> {'danceability': 0.311,
'energy': 0.325,
'key': 2,
'loudness': -9.042,
'mode': 1,
'speechiness': 0.0283
...}
@vlad-ds
vlad-ds / spoty.py
Last active February 1, 2020 17:53
def get_features(track_id: str, token: str) -> dict:
sp = spotipy.Spotify(auth=token)
try:
features = sp.audio_features([track_id])
return features[0]
except:
return None
@vlad-ds
vlad-ds / spoty.py
Last active February 1, 2020 17:53
lucy_id = get_id('Lucy', token, artist = 'The Beatles')
print(lucy_id)
>> '25yQPHgC35WNnnOUqFhgVR'