<commit_before>__author__ = 'matt'

from databaseAccess import *
import spotipy

class UserLikesBroker():

    def __init__(self):
        self.spotify = spotipy.Spotify()

    def saveUserLikes(self, artists, user):
        try:
            UserLikes.get(UserLikes.userID == user)
        except:
            artistURIs = self.getArtistURIs(artists)

            for uri in artistURIs:
                userlike = UserLikes.create(userID=user,artistURI=uri)
                userlike.save()

    def getArtistURIs(self, artists):
        artistURIs = []

        for artist in artists:
            results = self.spotify.search(q='artist:' + artist, type='artist')
            if len(results) > 0:
                artistsData = results['artists']
                if len(artistsData) > 0:
                    if len(artistsData['items']) > 0:
                        artistInfo = artistsData['items'][0]
                        artistURIs.append(artistInfo["uri"])

        return artistURIs<commit_msg>userLikesBroker - changes to track down source of FB userID bug<commit_after>__author__ = 'matt'

from databaseAccess import *
import spotipy

class UserLikesBroker():

    def __init__(self):
        self.spotify = spotipy.Spotify()

    def saveUserLikes(self, artists, user):
        try:
            UserLikes.get(UserLikes.userID == user)
        except:
            artistURIs = self.getArtistURIs(artists)

            for uri in artistURIs:
                print user
                userlike = UserLikes.create(userID=user,artistURI=uri)
                userlike.save()

    def getArtistURIs(self, artists):
        artistURIs = []

        for artist in artists:
            results = self.spotify.search(q='artist:' + artist, type='artist')
            if len(results) > 0:
                artistsData = results['artists']
                if len(artistsData) > 0:
                    if len(artistsData['items']) > 0:
                        artistInfo = artistsData['items'][0]
                        artistURIs.append(artistInfo["uri"])

        return artistURIs
{'fraction_non_alphanumeric': 0.09956709956709957, 'fraction_numerical': 0.003848003848003848, 'mean_word_length': 1.9131652661064427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5966499', 'n_tokens_mistral': 620, 'n_tokens_neox': 595, 'n_words': 126}