コード例 #1
0
ファイル: index.py プロジェクト: saintbyte/itunes_search
def album(id):
    r = AppleRequest()
    try:
        data_json = r.album(id)
    except ItunesGetProblemException:
        return resp_500('Connection itunes problem on get list songs')
    except:
        return resp_500('Internal Error on list songs')
    try:
        s_arr = json.loads(data_json)
    except:
        return resp_500('Internal Error on list songs on parse json')
    if (s_arr['resultCount'] == 0):
        resp_404('Songs not found')
    return resp_ok(data_json)
コード例 #2
0
ファイル: test1.py プロジェクト: saintbyte/itunes_search
def getArtistSearch(first_name,last_name):
    r = AppleRequest()
    try:
        data_json = r.searchArtist('{} {}'.format(first_name,last_name))
    except ItunesGetProblemException: 
        return 0
    except:
        return 0

    data_arr = json.loads(data_json)

    artist_full_name = ("{} {}".format(first_name,last_name)).lower()
    if (data_arr['resultCount'] == 0):
         return 0
    for artist in data_arr['results']:
        if (artist['artistName'].lower() == artist_full_name and \
            artist['artistType'] == 'Artist'):
            r.getAllAlbumsByArtistId(artist['artistId'])
            return artist['artistId']
    """
コード例 #3
0
ファイル: index.py プロジェクト: saintbyte/itunes_search
def find(first_name,last_name):
    r = AppleRequest()
    try:
        data_json = r.searchArtist('{} {}'.format(first_name,last_name))
    except ItunesGetProblemException:
        return resp_500('Connection itunes problem')
    except:
        return resp_500('Internal Error')
    try:
        data_arr = json.loads(data_json)
    except:
        return resp_500('Itunes json parse problem')
    artist_full_name = ("{} {}".format(first_name,last_name)).lower()
    if (data_arr['resultCount'] == 0):
        return resp_404('Artist not found')
    for artist in data_arr['results']:
        if (artist['artistName'].lower() == artist_full_name and \
            artist['artistType'] == 'Artist'):
            try:
                s = (r.getAllAlbumsByArtistId(artist['artistId'])).strip()
            except ItunesGetProblemException:
                return resp_500('Connection itunes problem on get list albums')
            except:
                return resp_500('Internal Error on list albums')
            try:
                m = hashlib.md5()
                m.update(s)
                search_id = m.hexdigest()
                s_arr = json.loads(s)
                s_arr['search_id'] = search_id
                s = json.dumps(s_arr)
                fh = open('search_id/{}'.format(search_id),'w')
                fh.write(s)
                fh.close()
            except:
                return resp_500('A not found')
            return resp_ok(s)
    return resp_404('Albums not found')