-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimporter_by_name.py
66 lines (52 loc) · 1.7 KB
/
importer_by_name.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from fuzzywuzzy import fuzz
import time
import sys
from xml_parser import (
parse_artists,
)
from muzooka_client import get_artist_by_name
def main(argv):
if len(argv) < 1:
print('Missing XML file input')
print('test_xml_artist.py <inputfile>')
sys.exit(2)
start_time = time.time()
count_artist = 0
count_artist_match = 0
count_artist_match_spotify_id = 0
ratio_match = 0.0
pathXML = argv[0]
artist_limit = 150
if len(argv) == 2:
artist_limit = int(argv[1])
print('Parsing artist file {}\n'.format(pathXML))
for artist in parse_artists(pathXML):
resp, mach = get_artist_by_name(artist['name'], artist.get('spotify_id'))
if mach:
count_artist_match_spotify_id += 1
count_artist += 1
if artist['name'] == resp['name']:
count_artist_match += 1
ratio = fuzz.token_sort_ratio(artist['name'], resp['name'])
ratio_match += ratio / 100
print(u'Artist {0}: Discogs: {1}({2}) - Muzooka: {3}({4}), ratio: {5}\n'.format(
count_artist,
artist['name'],
artist['id'],
resp['name'],
resp['facebookUsername'],
ratio,
))
if artist_limit == count_artist:
break
ratio_avarage = ratio_match / count_artist
elapsed_time = time.time() - start_time
print('Resume => \n count_artist: {0} \n count_artist_match: {1} \n ratio_avarage: {2} \n Elapsed time: {3} \n spotify hits {4}'.format(
count_artist,
count_artist_match,
ratio_avarage,
elapsed_time,
count_artist_match_spotify_id,
))
if __name__ == '__main__':
main(sys.argv[1:])