Пример #1
0
    def request_review(self, album_name):
        # connect to Discogs
        d = discogs_client.Client(self.app_name, user_token=self.user_token)

        # search Discogs for album
        results = d.search(album_name, type='release')
        search_results = []
        if len(results) == 0:
            print("Could not find album.")
        else:
            # extract artist's name
            artist = results[0].artists[0]
            artist_name = artist.name
            try:
                # search Pitchfork for review
                p = pitchfork.search(artist_name, album_name)
                search_results.append(artist_name)
                search_results.append(p.album())
                search_results.append(p.label())
                search_results.append(p.score())
            except Exception:
                print("Album not found in Pitchfork.")
                pass
            
        return search_results
Пример #2
0
def fetch_review(album, log, force):
    rating = album.get('pitchfork_score')
    if rating != None and rating != '' and not force:
        message = ui.colorize('text_highlight_minor',
                              u'has rating %s' % rating)
        log.info(u'{0}: {1}', album, message)
        return

    try:
        log.debug(u'Querying {0.albumartist} - {0.album}', album)
        review = search(album['albumartist'], album['album'])
        score = float(review.score())
    except IndexError as e:
        log.debug(u'No review found: {0}', e)
        message = ui.colorize('text_error', u'no review found')
        log.info(u'{0}: {1}', album, message)
        return
    except Exception as e:
        log.debug(u'Error trying to get review: {0}', e)
        message = ui.colorize('text_error', u'could not fetch review')
        log.info(u'{0}: {1}', album, message)
        return

    message = ui.colorize('text_success', u'found review %s' % review.score())
    album['pitchfork_bnm'] = review.best_new_music()
    album['pitchfork_description'] = review.abstract()
    album['pitchfork_score'] = score
    album['pitchfork_url'] = 'https://pitchfork.com%s' % review.url
    album.store()
    log.info(u'{0}: {1}', album, message)
Пример #3
0
def get_pitchfork_reviews(artist_name, album_names):
    """Get the artists reviews from pitchfork."""
    reviews = []
    for album_name in album_names:
        try:
            review = pitchfork.search(artist_name, album_name)
            reviews.append(review)
        except IndexError:
            print("Couldn't find {}".format(album_name))
    return reviews
Пример #4
0
def query(artist, title):
    print(artist, title)
    try:
        a = search(artist, title if title != 'Self-Titled' else artist)
        print(a)
        writer.writerow({
            'artist': artist,
            'album': title,
            'score': a.score(),
            'genres': a.genres()
        })
    except IndexError as e:
        print(e)
        writer.writerow({
            'artist': artist,
            'album': title,
            'score': 'SCORE ERROR',
            'genres': 'GENRES ERROR'
        })
Пример #5
0
def get_pitchfork_reviews(artist_name, album_names):
    """Get the artists reviews from pitchfork."""
    # this line is needed because the python requests library requires values to be ascii
    artist_name = unidecode(artist_name)
    reviews = []
    for album_name in album_names:
        try:
            album_name = unidecode(album_name)
            review = pitchfork.search(artist_name, album_name)
            reviews.append(review)
        except IndexError:
            print("Couldn't find {}".format(album_name))
    if len(reviews) > 0:
        temp = []
        for review in reviews:
            # This is necessary because sometimes albums with similar names
            # get added twice as the pitchfork API does fuzzy search
            if review not in temp:
                temp.append(review)
        reviews = temp
    return reviews
Пример #6
0
    def find_music_rating(self):
        '''
        Collects Pitchfork critic ratings to compare
        to the sentiment analysis if the query is
        an artist and album
        '''
        if ',' not in self.term:
            return
        artist = self.term.split(',')[0].strip()
        album = self.term.split(',')[1].strip()

        #~Pitchfork API package used from https://pypi.python.org/pypi/pitchfork/#

        # If the user tried to categorize a query as a book but
        # the query term is not in GoodReads, the program will
        # not be terminated, but no critic reviews will be displayed.
        try:
            p = pitchfork.search(album, artist)
        except:
            return
        self.pitchfork_rating = p.score() * 10
        return
Пример #7
0
    def find_music_rating(self):
        """
        Collects Pitchfork critic ratings to compare
        to the sentiment analysis if the query is
        an artist and album
        """
        if "," not in self.term:
            return
        artist = self.term.split(",")[0].strip()
        album = self.term.split(",")[1].strip()

        # ~Pitchfork API package used from https://pypi.python.org/pypi/pitchfork/#

        # If the user tried to categorize a query as a book but
        # the query term is not in GoodReads, the program will
        # not be terminated, but no critic reviews will be displayed.
        try:
            p = pitchfork.search(album, artist)
        except:
            return
        self.pitchfork_rating = p.score() * 10
        return
Пример #8
0
import pitchfork
import artistAnalysis
import unicodedata

listOfArtists = ['Kanye West']

for artist in listOfArtists:
    artistDetails = {}
    artistDetails["artist"] = artist
    individualArtistAlbums = pitchfork.allAlbums(artist)[::-1]
    for album in individualArtistAlbums:
        albumTitle = unicodedata.normalize('NFKD',
                                           album).encode('ascii', 'ignore')
        albumDetails = pitchfork.search(artist, albumTitle)
        if hasattr(albumDetails, 'score') == True:
            artistAnalysis.artistRateOfChangePerAlbum(albumDetails.timestamp,
                                                      artist, albumTitle,
                                                      albumDetails.score())

    # Create a spreadsheet with all artists
    # Controversy and non controversial point
    # Read the spreadsheet and run through Python
    # Check from Pitchfork
    # Analyze if they have a change in controversy after controversy point
    # Analyze if they have a long term drop
    # Save entire artist with Album to Database

    #Lingering Questions
    # How do I determine if someone is controversial
    #
Пример #9
0
import numpy as np
import codecs
import string

with open('C:\Users\kevin\Dropbox\Fun\p4k_1000.csv', 'rb') as f:
    reader = csv.reader(f)
    your_list = list(reader)
data = np.asarray(your_list)
authors = list()
texts = list()
scores = np.zeros(len(data))

yay = list()
for i in range(len(data)):
    try:
        p = pitchfork.search(artists[i], albums[i])
    except Exception:
        pass

    scores[i] = p.score()
    d = p.__dict__.copy()
    d['soup'] = d['soup'].prettify()
    author = p.soup.find(class_='info').h4.get_text()
    author = author[:author.index(';')].strip()
    authors.append(author)
    editorial = p.editorial()
    texts.append(editorial)

yay = list()
for i in range(len(texts)):
    xx = texts[i].encode('utf-8')
Пример #10
0
#!/usr/bin/env python
import pitchfork
import json
import csv
from progressbar import ProgressBar

artists = []
storedAlbums = []
reviews = []

p1 = pitchfork.search('a', '') # the title is autocompleted

char = 97 # ASCII for 'a'

# Python code to remove duplicate elements 
def remove(duplicate): 
    final_list = [] 
    for num in duplicate: 
        if num not in final_list: 
            final_list.append(num) 
    return final_list

# Open artists file
filepath = 'artists.txt'
with open(filepath) as fp:
    line = fp.readline()
    cnt = 0

# Store artists in array
    while line:
        artists.append(line.strip())
Пример #11
0
def results_page(request):
    """
        This is the view corresponding to the page that will appear when a user enters an artist into the search bar
    """

    # this is for the search bar on results page
    if request.method == 'GET':
        form = ArtistForm()
        if form.is_valid():
            return HttpResponseRedirect('/results/')
    else:
        form = ArtistForm()

    # Get whatever the user entered into the form, and store it into a variable
    artist = request.GET.items()[0][1]

    # Make three URLs to be requests to the Last FM API: top albums, similar artists, and top tags
    url = 'http://ws.audioscrobbler.com/2.0/?method=artist.gettopalbums&artist=' + artist + '&api_key=673c370b7184a43691df1c7c2b35874f&format=json'
    url2 = 'http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=' + artist + '&api_key=673c370b7184a43691df1c7c2b35874f&format=json'
    url3 = 'http://ws.audioscrobbler.com/2.0/?method=artist.gettoptags&artist=' + artist + '&api_key=673c370b7184a43691df1c7c2b35874f&format=json'

    # Make the three requests, storing the request objects in their corresponding variables
    topAlbumsRequest = requests.get(url)
    similarArtistsRequest = requests.get(url2)
    artistGenreList = requests.get(url3)

    # Make three empty lists for albums, similar artists, and genres, which will be passed into the template when rendered
    top_albums = []
    simArtist = []
    top_genre = []

    # First, append the main artist's genre to the genre list
    main_genre = artistGenreList.json()["toptags"]["tag"][0]["name"]

    # Add the top 5 results from the top albums request to the list
    for i in range(5):
        top_albums.append(
            topAlbumsRequest.json()["topalbums"]["album"][i]["name"])

    # For this loop, populate both the tags array and the similar artists array
    for j in range(3):

        # First, append the current similar artist to the simArtists array
        currSimArtist = similarArtistsRequest.json(
        )["similarartists"]["artist"][j]["name"]
        simArtist.append(currSimArtist)

        # Construct the request URL using the current similar artist's name
        reqUrl = 'http://ws.audioscrobbler.com/2.0/?method=artist.gettoptags&artist=' + currSimArtist + '&api_key=673c370b7184a43691df1c7c2b35874f&format=json'

        # Make the request
        topTagsRequest = requests.get(reqUrl)

        # Append the first tag to the tag list
        top_genre.append(topTagsRequest.json()["toptags"]["tag"][0]["name"])

    artist = topAlbumsRequest.json()["topalbums"]["@attr"]["artist"]

    pitchfork_ratings = []

    # Get the pitchfork ratings of each top album
    for album in top_albums:

        try:
            artist = artist.encode('ascii', 'ignore').decode('ascii')
            album = album.encode('ascii', 'ignore').decode('ascii')
            search = pitchfork.search(artist, album)
            pitchfork_ratings.append(search.score())

        except IndexError:
            pitchfork_ratings.append('N/A')

    # Zip the album list and the pitchfork rating list into one structure
    pitchfork_album_array = zip(top_albums, pitchfork_ratings)

    # Zip the similar artists and their genres together
    sim_artist_genre = zip(simArtist, top_genre)

    return render(
        request, 'results_page.html', {
            'pitchfork_albums': pitchfork_album_array,
            'sim_artist_genre': sim_artist_genre,
            'artist': artist,
            'main_genre': main_genre,
            'form': form
        })
Пример #12
0
def search(request, artist, album):
    review = pitchfork.search(url_argument_parse(artist), url_argument_parse(album))
    review_dictionary = {"artist": review.artist(), "album": review.album(), \
        "editorial": repair_editorial(review.editorial()), "label": review.label(), "score": review.score()}
    return JsonResponse(review_dictionary)
Пример #13
0
results = sp.search(q=input, limit=1, type='album')
if results is not None:
    if results['albums']['items']:
        id = results['albums']['items'][0]['id']
    else:
        print('TODO')
        #assign neutral values here
    album = sp.album(id)

    artist_id = album['artists'][0]['href']

    artist = sp.artist(artist_id)

    try:
        if (len(input) < 6):
            p = pitchfork.search(artist, input)
        else:
            p = pitchfork.search(artist, input[:5])

        pitchfork_score = p.score()
    except Exception:
        pitchfork_score = 0.0

    if artist['followers']['total']:
        followers = artist['followers']['total']
    else:
        followers = 0

    if artist['genres']:
        genres = artist['genres']
    else:
Пример #14
0
def search(request, artist, album):
    review = pitchfork.search(url_argument_parse(artist),
                              url_argument_parse(album))
    review_dictionary = {"artist": review.artist(), "album": review.album(), \
        "editorial": repair_editorial(review.editorial()), "label": review.label(), "score": review.score()}
    return JsonResponse(review_dictionary)
Пример #15
0
def get_score(album, artist):
    try:
        rec = pitchfork.search(artist, album)
        return rec.score()
    except IndexError:
        print(f"Cannot find album \"{album}\" by {artist}")
 def com_pfork_search(self, artist_name, album_title):
     """
     Search via name and title
     """
     self.pitchfork_api = pitchfork.search(artist_name, album_title)
Пример #17
0
def album_scrape_p(name, album):
    '''takes artist and album and creates dict for each 
    album available on pitchfork 
    Parameters:
    _artist <str> - Artist Name
    _album <album name> - Artist's specificed album 
    Returns:
    _album_content <Album> - contains all info 
    necessary for db add 
    '''
    p = pitchfork.search(name, album)  # the title is autocompleted
    try:
        try:
            x = p.year()
        except:
            x = 0000
        if len(x) != 4:
            try:
                y = x.split('-').strip()
                x = y[0]
                x = int(x)
            except:
                x = 0000
        try:
            g = p.editorial()
            #mf = g.replace('/','')
        except:
            g = "No Review"
        try:
            title = p.album()  # the full album title
        except:
            title = album
        try:
            label = p.label()
        except:
            label = 'No Label'
        try:
            rating = p.score()
        except:
            rating = 5.0
        try:
            artist = p.artist()
        except:
            artist = name
        try:
            year = int(x)
        except:
            year = 0000
        try:
            cover = p.cover()
        except:
            cover = 'None'
    except:
        print('ERROR')
    return Album(title=title,
                 label=label,
                 edit=g,
                 cover=cover,
                 year=year,
                 rating=rating,
                 artist=artist)