Glider
Loading...
Searching...
No Matches
QobuzTemplate.py
Go to the documentation of this file.
1import re
2import awswrangler as wr
3from datetime import datetime
4
6 def type(self, asset_type, filename):
7 """Maps the sale type with the name specified by the client according their requirements
8 Args:
9 asset_type (str): sale type shown in the original file
10 filename (str): current filename, it says if file contains streaming or downloads
11 Returns: (sale type in a single one letter)
12 """
13 if "download" in filename:
14 if asset_type=="track":
15 return 'T'
16 elif asset_type=="album":
17 return 'A'
18 return 'S'
19
20 def assetType(self, df, filename):
21 """Applies type functions to current dataframe
22 Args:
23 df (pandas dataframe): dataframe where changes will applied
24 Returns: df (pandas dataframe)
25 """
26 # Add a new column to insert type
27 df["asset_type"] = df.apply(lambda Row: self.type(Row['album or track'], filename), axis=1)
28 return df
29
30 def date(self, filename):
31 """Sets date column given the filename (it contains the date)
32 For example qobuz-eu-gyrost-202205-streaming.tsv
33 Args:
34 filename (str): current filename
35 Returns: date_str (str)
36 """
37 # "qobuz-eu-gyrost-202205-streaming.tsv"
38 date = re.findall(r'-20\d{4}', filename)[0]
39 date = date.replace("-", "")
40 date_str = date[:4]+"-"+date[4:6]
41 # df["date_from_file"] = date_str
42 return date_str