<commit_before># -*- coding: utf-8 -*-
"""
Created on Thu Aug 07 21:08:10 2014

@author: Andrew
"""

import json
import urllib2
import scrape_songs
#import webbrowser

def create_playlist():
    artists, titles = scrape_songs.scrape_cd1025_songs(10)
    if len(artists) != len(titles):
        raise Exception("Artists and titles don't match")
    
    spotify_search_base = "https://api.spotify.com/v1/search?q="
    #i=len(artists)-1
    #i=1
    ids = []
    for i in range(len(artists)):
        song_search = "artist:" + artists[i].replace(" ", "%20") + "%20track:" + titles[i].replace(" ", "%20")
        url = spotify_search_base + song_search + "&type=track&limit=1"
        data = json.load(urllib2.urlopen(url))
        try:
            ids.append(data['tracks']['items'][0]['id'])
        except IndexError:
            print "Could not find " + artists[i] + " - " + titles[i]
    
    playlist_base = "https://embed.spotify.com/?uri=spotify:trackset:RadioPlaylist:"
    playlist_url = playlist_base + ",".join(ids)
    return playlist_url
    
#    webbrowser.open(playlist_url, new = 2)<commit_msg>reduced songs<commit_after># -*- coding: utf-8 -*-
"""
Created on Thu Aug 07 21:08:10 2014

@author: Andrew
"""

import json
import urllib2
import scrape_songs
#import webbrowser

def create_playlist():
    artists, titles = scrape_songs.scrape_wxrt_songs(5)
    if len(artists) != len(titles):
        raise Exception("Artists and titles don't match")
    
    spotify_search_base = "https://api.spotify.com/v1/search?q="
    #i=len(artists)-1
    #i=1
    ids = []
    for i in range(len(artists)):
        song_search = "artist:" + artists[i].replace(" ", "%20") + "%20track:" + titles[i].replace(" ", "%20")
        url = spotify_search_base + song_search + "&type=track&limit=1"
        data = json.load(urllib2.urlopen(url))
        try:
            ids.append(data['tracks']['items'][0]['id'])
        except IndexError:
            print "Could not find " + artists[i] + " - " + titles[i]
    
    playlist_base = "https://embed.spotify.com/?uri=spotify:trackset:RadioPlaylist:"
    playlist_url = playlist_base + ",".join(ids)
    return playlist_url
    
#    webbrowser.open(playlist_url, new = 2)
#if __name__ == "__main__":
#    pl = create_playlist()
#    print pl
{'fraction_non_alphanumeric': 0.16033202271734381, 'fraction_numerical': 0.026649191786806466, 'mean_word_length': 3.1712204007285973, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2084070', 'n_tokens_mistral': 841, 'n_tokens_neox': 796, 'n_words': 159}