-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathutils.py
More file actions
27 lines (26 loc) · 1.13 KB
/
utils.py
File metadata and controls
27 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
__author__ = 'tal'
def makePrecise(query,results):
'''
:param query: the query searched for
:param results: the result set returned by the itunes api
:return:results that are an exact match
'''
f =filter(lambda x: x.name==query,results)
return [res for res in f]
def filterOn(key,val,results,case_insensitive=False,substring=False):
'''
Allows filtering of itunes results by a second field. (Can be applied multiple times)
Useful when your retreive a track by name and want to filter by artist
:param key: The key you want to filter by
:param val: The value that key should be
:param results: The results set returned by itunes
:param case_insensitive: Case insensitive filter
:param substring: if True, check if the value is a substring of the field
:return:The filtered result set
'''
lower = (lambda x: x.lower()) if case_insensitive is True else (lambda x: x)
match = (lambda x,y: x in y) if substring is True else (lambda x,y: x==y)
val = lower(val)
print (val)
f =filter(lambda x: match(val,lower(x.__getattribute__(key).name)),results)
return [res for res in f]