Skip to content

Instantly share code, notes, and snippets.

View vlad-ds's full-sized avatar

Vlad Gheorghe vlad-ds

View GitHub Profile
@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:26
{
"endTime" : "2019–01–26 07:49",
"artistName" : "Tom Waits",
"trackName" : "Heartattack And Vine",
"msPlayed" : 8850
}
print(token)
>> T2_wi8XsUpJrbD0BHQH4vX0BrSuYV0D88sVrQ_wMgApU...
@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
@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
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 / SETUP_DAY.md
Created January 8, 2021 09:47
Starting my coding journey...
@vlad-ds
vlad-ds / SETUP_DAY.md
Created January 11, 2021 11:51
Starting my coding journey...
@vlad-ds
vlad-ds / fizzbuzz.py
Created April 7, 2021 08:28
A Cooler Fizzbuzz
def fizzbuzz(n):
return [('' + 'Fizz' * (not x % 3) + 'Buzz' * (not x % 5)) or x for x in range(1, n+1)]
@vlad-ds
vlad-ds / bq_query_1.sql
Created May 11, 2022 16:09
BigQuery SQL 1
SELECT term,
rank,
AVG(score) AS avg_score
FROM `bigquery-public-data.google_trends.international_top_terms`
WHERE refresh_date = DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY)
AND country_name = "United Kingdom"
GROUP BY term, rank
ORDER BY rank ASC;